How to use fromBinaryFile method of com.tngtech.jgiven.attachment.Attachment class

Best JGiven code snippet using com.tngtech.jgiven.attachment.Attachment.fromBinaryFile

Source:Html5AttachmentGeneratorTest.java Github

copy

Full Screen

...52 StepModel stepModel = new StepModel("test", Lists.newArrayList());53 stepModel.addAttachment(attachment);54 generator.visit(stepModel);55 File writtenFile = new File(temporaryFolderRule.getRoot().getPath() + "/attachment-thumb.gif");56 Attachment writtenAttachment = Attachment.fromBinaryFile(writtenFile, MediaType.GIF);57 BufferedImage after = ImageIO.read(new ByteArrayInputStream(BaseEncoding.base64()58 .decode(writtenAttachment.getContent())));59 assertThat(after.getWidth()).isEqualTo(MINIMAL_THUMBNAIL_SIZE);60 assertThat(after.getHeight()).isEqualTo(MINIMAL_THUMBNAIL_SIZE);61 }62 @Test63 public void testFindingAndGeneratingAttachmentsInAllSteps() throws IOException {64 File root = temporaryFolderRule.getRoot();65 generator.generateAttachments(root, generateReportModelWithAttachments());66 File parentStepFile = new File(temporaryFolderRule.getRoot().getPath()67 + "/attachments/testing/parentAttachment.gif");68 File nestedStepFile = new File(temporaryFolderRule.getRoot().getPath()69 + "/attachments/testing/nestedAttachment.gif");70 Attachment writtenParentAttachment = Attachment.fromBinaryFile(parentStepFile, MediaType.GIF);71 Attachment writtenNestedAttachment = Attachment.fromBinaryFile(nestedStepFile, MediaType.GIF);72 assertThat(writtenParentAttachment.getContent()).isNotNull();73 assertThat(writtenNestedAttachment.getContent()).isNotNull();74 }75 @Test76 public void testGetImageDimensions() {77 assertThat(generator.getImageDimension(BINARY_SAMPLE)).isEqualTo(new Dimension(22, 22));78 }79 @Test80 public void testPNGConvertor() {81 File sampleSVG = new File("src/test/resources/SampleSVG.svg");82 String pngContent = generator.getPNGFromSVG(sampleSVG);83 assertThat(generator.getImageDimension(BaseEncoding.base64().decode(pngContent)))84 .isEqualTo(new Dimension(25, 25));85 }...

Full Screen

Full Screen

Source:ThenPhotoBoothDisplaysPictures.java Github

copy

Full Screen

...5import java.io.File;6import java.io.IOException;7import java.net.URISyntaxException;8import static com.google.common.io.Resources.getResource;9import static com.tngtech.jgiven.attachment.Attachment.fromBinaryFile;10import static com.tngtech.jgiven.attachment.MediaType.PNG;11import static org.assertj.core.api.Assertions.assertThat;12import static org.assertj.core.api.Assertions.contentOf;13public class ThenPhotoBoothDisplaysPictures<SELF extends ThenPhotoBoothDisplaysPictures<?>> extends Stage<SELF> {14 @ExpectedScenarioState15 private CurrentStep currentStep;16 @ExpectedScenarioState17 private File processedPicture;18 public SELF the_picture_should_be_displayed_four_times() throws Exception {19 assertExpectedPicture("dog-identity.jpeg", "Identity picture");20 return self();21 }22 public SELF the_photo_booth_should_allow_the_photo_taking() {23 assertThat(processedPicture.isFile()).isTrue();24 assertThat(processedPicture.exists()).isTrue();25 return self();26 }27 public SELF a_sepia_effect_should_be_apply_to_the_picture() throws IOException, URISyntaxException {28 assertExpectedPicture("dog-sepia.jpeg", "Sepia picture");29 return self();30 }31 public SELF the_picture_should_be_displayed_sixteen_times() throws IOException, URISyntaxException {32 assertExpectedPicture("dog-mini.jpeg", "Mini picture");33 return self();34 }35 private void assertExpectedPicture(String pictureName, String tooltipTitle) throws URISyntaxException, IOException {36 final File expectedPicture = getPicture(pictureName);37 assertThat(contentOf(processedPicture)).isEqualTo(contentOf(expectedPicture));38 currentStep.addAttachment(39 fromBinaryFile(expectedPicture, PNG)40 .withTitle(tooltipTitle)41 .showDirectly()42 );43 }44 private File getPicture(String resourceName) throws URISyntaxException {45 return new File(getResource(resourceName).toURI());46 }47}...

Full Screen

Full Screen

Source:AttachmentTest.java Github

copy

Full Screen

...25 Files.write( HELLO_JGIVEN, textFile, Charsets.UTF_8 );26 }27 @Test28 public void testBinaryConverter() throws IOException {29 Attachment attachment = Attachment.fromBinaryFile( binaryFile, ARBITRARY_MEDIA_TYPE );30 assertThat( attachment.getContent() ).isEqualTo( "AwQMFw==" );31 attachment = Attachment.fromBinaryBytes( ARBITRARY_BYTES, ARBITRARY_MEDIA_TYPE );32 assertThat( attachment.getContent() ).isEqualTo( "AwQMFw==" );33 }34 @Test35 public void testTextConverter() throws IOException {36 assertThat( Attachment.fromTextFile( textFile, MediaType.PLAIN_TEXT_UTF_8 ).getContent() ).isEqualTo( HELLO_JGIVEN );37 assertThat( Attachment.xml( HELLO_JGIVEN ).getContent() ).isEqualTo( HELLO_JGIVEN );38 assertThat( Attachment.json( HELLO_JGIVEN ).getContent() ).isEqualTo( HELLO_JGIVEN );39 }40}...

Full Screen

Full Screen

fromBinaryFile

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.attachment.Attachment;2import com.tngtech.jgiven.attachment.MediaType;3import com.tngtech.jgiven.attachment.Attachment;4import com.tngtech.jgiven.attachment.MediaType;5import java.io.File;6import java.io.IOException;7import java.nio.file.Files;8import java.nio.file.Path;9import java.nio.file.Paths;10import java.nio.file.StandardOpenOption;11import java.util.Base64;12import java.util.Base64.Decoder;13import java.util.Base64.Encoder;14import java.util.logging.Level;15import java.util.logging.Logger;16public class JGivenAttachment {17 public static void main(String[] args) {18 String encodedFile = encodeFileToBase64Binary("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");19 Attachment attachment = Attachment.fromBinaryFile(encodedFile, "Desert.jpg", MediaType.JPG);20 System.out.println(attachment.getContent());21 }22 public static String encodeFileToBase64Binary(String fileName) {23 File file = new File(fileName);24 Path path = Paths.get(file.getAbsolutePath());25 byte[] bytes;26 try {27 bytes = Files.readAllBytes(path);28 Encoder encoder = Base64.getEncoder();29 String encodedFile = encoder.encodeToString(bytes);30 return encodedFile;31 } catch (IOException ex) {32 Logger.getLogger(JGivenAttachment.class.getName()).log(Level.SEVERE, null, ex);33 }34 return null;35 }36}37data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2w

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful