pvillard31 commented on code in PR #11030:
URL: https://github.com/apache/nifi/pull/11030#discussion_r2987317828


##########
nifi-extension-bundles/nifi-compress-bundle/nifi-compress-processors/src/test/java/org/apache/nifi/processors/compress/TestModifyCompression.java:
##########
@@ -407,6 +434,41 @@ void testWhereDecompressionNotNeeded(Relationship 
toRelationship) throws Excepti
         runner.assertAllFlowFilesTransferred(expectedRelationship, 1);
     }
 
+    @Test
+    void testXzlzma2DecompressWithMimeType() throws Exception {
+        final String content = "Content for compression";
+        final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
+        final LZMA2Options options = new LZMA2Options();
+        final ByteArrayOutputStream compressedOutput = new 
ByteArrayOutputStream();
+        try (XZOutputStream xzOut = new XZOutputStream(compressedOutput, 
options)) {
+            xzOut.write(contentBytes, 0, contentBytes.length);
+            xzOut.finish();
+        }
+
+        runner.setProperty(ModifyCompression.INPUT_COMPRESSION_STRATEGY, 
CompressionStrategy.MIME_TYPE_ATTRIBUTE);
+        runner.setProperty(ModifyCompression.OUTPUT_FILENAME_STRATEGY, 
FilenameStrategy.UPDATED);
+        final Map<String, String> attributes = 
Map.of(CoreAttributes.MIME_TYPE.key(), "application/x-xz");
+        runner.enqueue(compressedOutput.toByteArray(), attributes);
+
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(ModifyCompression.REL_SUCCESS, 1);
+        final MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();
+        flowFile.assertContentEquals(content);
+    }
+
+    @Test
+    public void testXzlzma2Compress() {
+        runner.setProperty(ModifyCompression.OUTPUT_COMPRESSION_STRATEGY, 
CompressionStrategy.XZ_LZMA2);
+        final String content = "Content for compression";
+        runner.enqueue(content);
+        runner.run();
+
+        runner.assertAllFlowFilesTransferred(ModifyCompression.REL_SUCCESS, 1);
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();

Review Comment:
   ```suggestion
           final MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();
   ```



##########
nifi-extension-bundles/nifi-compress-bundle/nifi-compress-processors/src/test/java/org/apache/nifi/processors/compress/TestModifyCompression.java:
##########
@@ -407,6 +434,41 @@ void testWhereDecompressionNotNeeded(Relationship 
toRelationship) throws Excepti
         runner.assertAllFlowFilesTransferred(expectedRelationship, 1);
     }
 
+    @Test
+    void testXzlzma2DecompressWithMimeType() throws Exception {

Review Comment:
   ```suggestion
       public void testXzlzma2DecompressWithMimeType() throws Exception {
   ```



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java:
##########
@@ -216,33 +224,33 @@ public void testGzipDecompress() throws Exception {
         runner.setProperty(CompressContent.COMPRESSION_FORMAT, "gzip");
         assertTrue(runner.setProperty(CompressContent.UPDATE_FILENAME, 
"true").isValid());
 
-        
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt.gz"));
+        runner.enqueue(SAMPLE_GZ_FILE);
         runner.run();
 
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
-        
flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
+        flowFile.assertContentEquals(SAMPLE_TEXT_FILE);
         flowFile.assertAttributeEquals("filename", "SampleFile.txt");
 
         runner.clearTransferState();
         
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile1.txt.gz"));
         runner.run();
 
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
-        
flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
+        flowFile.assertContentEquals(SAMPLE_TEXT_FILE);
         flowFile.assertAttributeEquals("filename", "SampleFile1.txt");
 
         runner.clearTransferState();
         runner.setProperty(CompressContent.COMPRESSION_FORMAT, 
CompressContent.COMPRESSION_FORMAT_ATTRIBUTE);
         Map<String, String> attributes = new HashMap<>();
         attributes.put(CoreAttributes.MIME_TYPE.key(), "application/x-gzip");

Review Comment:
   ```suggestion
   Map<String, String> attributes = Map.of(CoreAttributes.MIME_TYPE.key(), 
"application/x-gzip");
   ```



##########
nifi-extension-bundles/nifi-compress-bundle/nifi-compress-processors/src/main/java/org/apache/nifi/processors/compress/ModifyCompression.java:
##########
@@ -168,7 +167,7 @@ public class ModifyCompression extends AbstractProcessor {
             REL_FAILURE
     );
 
-    private static final Map<String, CompressionStrategy> 
compressionFormatMimeTypeMap;
+    static final Map<String, CompressionStrategy> compressionFormatMimeTypeMap;

Review Comment:
   ```suggestion
       private static final Map<String, CompressionStrategy> 
compressionFormatMimeTypeMap;
   ```



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java:
##########
@@ -70,11 +78,11 @@ public void testSnappyHadoopCompress() throws Exception {
         runner.setProperty(CompressContent.COMPRESSION_FORMAT, 
CompressContent.COMPRESSION_FORMAT_SNAPPY_HADOOP);
         runner.setProperty(CompressContent.UPDATE_FILENAME, "true");
 
-        
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        runner.enqueue(SAMPLE_TEXT_FILE);
         runner.run();
 
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();

Review Comment:
   ```suggestion
           final MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
   ```



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java:
##########
@@ -399,8 +407,49 @@ public void testBrotliDecompress() throws Exception {
         
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt.br"));
         runner.run();
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
-        
flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
+        flowFile.assertContentEquals(SAMPLE_TEXT_FILE);
         flowFile.assertAttributeEquals("filename", "SampleFile.txt");
     }
+
+    @Test
+    void testXzlzma2DecompressWithMimeType() throws Exception {
+        final String content = "Content for compression";
+        final byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
+        final LZMA2Options options = new LZMA2Options();
+        final ByteArrayOutputStream compressedOutput = new 
ByteArrayOutputStream();
+        try (XZOutputStream xzOut = new XZOutputStream(compressedOutput, 
options)) {
+            xzOut.write(contentBytes, 0, contentBytes.length);
+            xzOut.finish();
+        }
+
+        final TestRunner runner = 
TestRunners.newTestRunner(CompressContent.class);
+        runner.setProperty(CompressContent.MODE, "decompress");
+        runner.setProperty(CompressContent.COMPRESSION_FORMAT, 
CompressContent.COMPRESSION_FORMAT_ATTRIBUTE);
+
+        final Map<String, String> attributes = new HashMap<>();
+        attributes.put("mime.type", "application/x-xz");

Review Comment:
   ```suggestion
           final Map<String, String> attributes = Map.of("mime.type", 
"application/x-xz");
   ```



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java:
##########
@@ -31,18 +36,21 @@
 
 public class TestCompressContent {
 
+    private static final Path SAMPLE_TEXT_FILE = 
Paths.get("src/test/resources/CompressedData/SampleFile.txt");
+    private static final Path SAMPLE_GZ_FILE = 
Paths.get("src/test/resources/CompressedData/SampleFile.txt.gz");
+
     @Test
     public void testSnappyCompress() throws Exception {
         final TestRunner runner = 
TestRunners.newTestRunner(CompressContent.class);
         runner.setProperty(CompressContent.MODE, 
CompressContent.MODE_COMPRESS);
         runner.setProperty(CompressContent.COMPRESSION_FORMAT, 
CompressContent.COMPRESSION_FORMAT_SNAPPY);
         runner.setProperty(CompressContent.UPDATE_FILENAME, "true");
 
-        
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        runner.enqueue(SAMPLE_TEXT_FILE);
         runner.run();
 
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();

Review Comment:
   ```suggestion
           final MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
   ```



##########
nifi-extension-bundles/nifi-compress-bundle/nifi-compress-processors/src/test/java/org/apache/nifi/processors/compress/TestModifyCompression.java:
##########
@@ -51,6 +56,28 @@ public void setRunner() {
         runner = TestRunners.newTestRunner(ModifyCompression.class);
     }
 
+    @Test
+    void testCompressionFormatMimeTypeMap() {

Review Comment:
   I do not think this test brings anything really useful and by removing it we 
can keep private scope on the variable



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java:
##########
@@ -399,8 +407,49 @@ public void testBrotliDecompress() throws Exception {
         
runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt.br"));
         runner.run();
         runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1);
-        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0);
-        
flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt"));
+        MockFlowFile flowFile = 
runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).getFirst();
+        flowFile.assertContentEquals(SAMPLE_TEXT_FILE);
         flowFile.assertAttributeEquals("filename", "SampleFile.txt");
     }
+
+    @Test
+    void testXzlzma2DecompressWithMimeType() throws Exception {

Review Comment:
   ```suggestion
       public void testXzlzma2DecompressWithMimeType() throws Exception {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to