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

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

Source:ScenarioExecutionTest.java Github

copy

Full Screen

...231 steps.add_attachment();232 List<AttachmentModel> attachments = getScenario().getScenarioCaseModel().getFirstStep().getAttachments();233 assertThat( attachments ).hasSize( 1 );234 assertThat( attachments.get( 0 ).getValue() ).isEqualTo( "FOOBAR" );235 assertThat( attachments.get( 0 ).getMediaType() ).isEqualTo( MediaType.PLAIN_TEXT_UTF_8.asString() );236 }237 @Test238 public void extended_descriptions_can_be_set_using_the_current_step() {239 AttachmentStepClass steps = addStage( AttachmentStepClass.class );240 steps.set_description();241 String description = getScenario().getScenarioCaseModel().getFirstStep().getExtendedDescription();242 assertThat( description ).isEqualTo( "An extended description" );243 }244 @Test245 public void the_name_of_a_step_can_be_changed_using_the_current_step() {246 AttachmentStepClass steps = addStage( AttachmentStepClass.class );247 steps.set_name();248 String description = getScenario().getScenarioCaseModel().getFirstStep().getName();249 assertThat( description ).isEqualTo( "A new step name" );...

Full Screen

Full Screen

Source:Html5AttachmentGenerator.java Github

copy

Full Screen

...57 writeAttachment(attachment);58 }59 }60 private void writeAttachment(AttachmentModel attachment) {61 String mimeType = attachment.getMediaType();62 MediaType mediaType = MediaType.parse(mimeType);63 File targetFile = writeFile(attachment, mediaType);64 attachment.setValue(htmlSubDir + "/" + targetFile.getName());65 log.debug("Attachment written to " + targetFile);66 }67 private String getExtension(MediaType mediaType) {68 if (mediaType.is(MediaType.SVG_UTF_8)) {69 return "svg";70 }71 if (mediaType.is(MediaType.ICO)) {72 return "ico";73 }74 if (mediaType.is(MediaType.BMP)) {75 return "bmp";76 }77 return mediaType.subtype();78 }79 File getTargetFile(String fileName, String extension) {80 if (fileName == null) {81 fileName = "attachment";82 }83 int count = fileCounter.count(fileName);84 fileCounter.add(fileName);85 String suffix = "";86 if (count > 0) {87 count += 1;88 suffix = String.valueOf(count);89 }90 String fileNameWithExtension = fileName + suffix + "." + extension;91 while (usedFileNames.contains(fileNameWithExtension)) {92 fileCounter.add(fileName);93 count++;94 suffix = String.valueOf(count);95 fileNameWithExtension = fileName + suffix + "." + extension;96 }97 usedFileNames.add(fileNameWithExtension);98 return new File(attachmentsDir, fileNameWithExtension);99 }100 private File getThumbnailFileFor(File originalImage) {101 String orgName = originalImage.getName();102 String newName = "";103 int dotIndex = orgName.lastIndexOf(".");104 if (dotIndex == -1) {105 newName = orgName + "-thumb";106 } else {107 String extension = orgName.subSequence(dotIndex + 1, orgName.length()).toString();108 newName = orgName.substring(0, dotIndex) + "-thumb." + extension;109 }110 return new File(attachmentsDir, newName);111 }112 private File writeFile(AttachmentModel attachment, MediaType mediaType) {113 String extension = getExtension(mediaType);114 File targetFile = getTargetFile(attachment.getFileName(), extension);115 try {116 if (attachment.isBinary()) {117 if (mediaType.is(MediaType.ANY_IMAGE_TYPE)) {118 File thumbFile = getThumbnailFileFor(targetFile);119 byte[] thumbnail = compressToThumbnail(attachment.getValue(), extension);120 Files.write(thumbnail, thumbFile);121 }122 Files.write(BaseEncoding.base64().decode(attachment.getValue()), targetFile);123 } else {124 Files.write(attachment.getValue().getBytes(Charsets.UTF_8), targetFile);125 if (com.tngtech.jgiven.attachment.MediaType.SVG_UTF_8.toString().equals(attachment.getMediaType())) {126 File thumbFile = getThumbnailFileFor(targetFile);127 writeThumbnailForSVG(targetFile, thumbFile);128 }129 }130 } catch (IOException e) {131 log.error("Error while trying to write attachment to file " + targetFile, e);132 }133 return targetFile;134 }135 private byte[] compressToThumbnail(String base64content, String extension) {136 byte[] imageBytes = BaseEncoding.base64().decode(base64content);137 byte[] base64thumb = {};138 try {139 BufferedImage before = ImageIO.read(new ByteArrayInputStream(imageBytes));...

Full Screen

Full Screen

Source:Attachment.java Github

copy

Full Screen

...81 /**82 * The type of the attachment. 83 * It depends on the reporter how this information is used.84 */85 public MediaType getMediaType() {86 return mediaType;87 }88 /**89 * An optional title of the attachment.90 * The title can be used by reporters, e.g. as a tooltip.91 * Can be {@code null}.92 */93 public String getTitle() {94 return title;95 }96 /**97 * An optional filename for the attachment.98 * Can be {@code null}.99 */100 public String getFileName() {101 return fileName;102 }103 /**104 * An optional filename for the attachment without the file type suffix.105 * The name can be used by reporters. 106 * 107 * @since 0.9.3108 */109 public Attachment withFileName( String fileName ) {110 this.fileName = fileName;111 return this;112 }113 /**114 * Sets the title and returns {@code this}115 */116 public Attachment withTitle( String title ) {117 this.title = title;118 return this;119 }120 /**121 * Directly shows this attachment in the report.122 * By default, the attachment is not directly shown in the scenario, 123 * but referenced by a link.124 * <p>125 * Note: This currently works only for images!126 * </p>127 * @throws com.tngtech.jgiven.exception.JGivenWrongUsageException if the attachment is not an image128 * @return {@code this}129 * @since 0.8.2130 */131 public Attachment showDirectly() {132 if( !this.getMediaType().isImage() ) {133 throw new JGivenWrongUsageException( "Only images can be directly shown" );134 }135 this.showDirectly = true;136 return this;137 }138 /**139 * Creates an attachment from a given array of bytes.140 * The bytes will be Base64 encoded.141 * @throws java.lang.IllegalArgumentException if mediaType is not binary142 */143 public static Attachment fromBinaryBytes( byte[] bytes, MediaType mediaType ) {144 if( !mediaType.isBinary() ) {145 throw new IllegalArgumentException( "MediaType must be binary" );146 }...

Full Screen

Full Screen

getMediaType

Using AI Code Generation

copy

Full Screen

1public class Test {2 public static void main(String[] args) {3 Attachment attachment = new Attachment();4 attachment.getMediaType();5 }6}7Exception in thread "main" java.lang.NoSuchMethodError: com.tngtech.jgiven.attachment.Attachment.getMediaType()Ljava/lang/String;8 at Test.main(Test.java:7)9public class Test {10 public static void main(String[] args) {

Full Screen

Full Screen

getMediaType

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.attachment;2import org.testng.annotations.Test;3public class AttachmentTest {4public void testGetMediaType() {5 Attachment attachment = new Attachment();6 attachment.getMediaType();7}8}9at com.tngtech.jgiven.attachment.Attachment.getMediaType(Attachment.java:25)10at com.tngtech.jgiven.attachment.AttachmentTest.testGetMediaType(AttachmentTest.java:15)11package com.tngtech.jgiven.attachment;12import org.testng.annotations.Test;13public class AttachmentTest {14public void testGetMediaType() {15 Attachment attachment = new Attachment();16 attachment.getMediaType();17}18}19at com.tngtech.jgiven.attachment.Attachment.getMediaType(Attachment.java:25)20at com.tngtech.jgiven.attachment.AttachmentTest.testGetMediaType(AttachmentTest.java:15)

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