-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#30196 add tests for ImageFilterExporter
- Loading branch information
1 parent
cb449e7
commit 8d0dcf4
Showing
2 changed files
with
1,674 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
.../java/com/dotmarketing/portlets/contentlet/business/exporter/ImageFilterExporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.dotmarketing.portlets.contentlet.business.exporter; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.dotmarketing.portlets.contentlet.business.BinaryContentExporter.BinaryContentExporterData; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Unit tests for the ImageFilterExporter class. | ||
*/ | ||
class ImageFilterExporterTest { | ||
|
||
private ImageFilterExporter exporter; | ||
|
||
/** | ||
* Set up the ImageFilterExporter instance before each test. | ||
*/ | ||
@BeforeEach | ||
public void setUp() { | ||
exporter = new ImageFilterExporter(); | ||
} | ||
|
||
/** | ||
* Given a valid SVG image file and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result without modifying the image. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithSvgImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.svg"); | ||
File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertTrue(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should not be transformed | ||
} | ||
|
||
/** | ||
* Given a valid EPS image file and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result without modifying the image. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithEpsImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.eps"); | ||
final File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
final BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertTrue(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should not be transformed | ||
} | ||
|
||
/** | ||
* Given a valid non-vector image file (JPG) and a set of parameters, | ||
* When exporting the content of the image, | ||
* Then the method should return a result with the image transformed. | ||
* | ||
* @throws Exception if an error occurs during export. | ||
*/ | ||
@Test | ||
void testExportContentWithNonVectorImage() throws Exception { | ||
// Given | ||
final URL url = getClass().getResource("/images/test.jpg"); | ||
final File inputFile = new File(Objects.requireNonNull(url).getFile()); | ||
Map<String, String[]> parameters = getSampleParameters(); | ||
|
||
// When | ||
final BinaryContentExporterData result = exporter.exportContent(inputFile, parameters); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertFalse(FileUtils.contentEquals(inputFile, result.getDataFile())); // The file should be transformed | ||
} | ||
|
||
/** | ||
* Helper method to provide a sample parameters map for use in the exportContent tests. | ||
* | ||
* @return a Map containing sample parameters. | ||
*/ | ||
final Map<String, String[]> getSampleParameters() { | ||
Map<String, String[]> parameters = new HashMap<>(); | ||
parameters.put("contentAsset", new String[]{"image"}); | ||
parameters.put("r", new String[]{"1728068872149"}); | ||
parameters.put("e5150266-7e28-445b-b5dd-193dc38922c7", new String[]{"asset"}); | ||
parameters.put("byInode", new String[]{"true"}); | ||
parameters.put("resize_w", new String[]{"500"}); | ||
parameters.put("quality_q", new String[]{"50"}); | ||
parameters.put("webp_q", new String[]{"50"}); | ||
parameters.put("fieldVarName", new String[]{"asset"}); | ||
parameters.put("assetInodeOrIdentifier", new String[]{"e5150266-7e28-445b-b5dd-193dc38922c7"}); | ||
return parameters; | ||
} | ||
} |
Oops, something went wrong.