Java Code Examples for org.apache.nifi.util.MockFlowFile#getAttributes()

The following examples show how to use org.apache.nifi.util.MockFlowFile#getAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtractImageMetadataTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractJPG() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/simple.jpg", ExtractImageMetadata.SUCCESS,null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("800 pixels", attributes.get(JPEG_HEADER + "Image Width"));
    assertEquals("600 pixels", attributes.get(JPEG_HEADER + "Image Height"));
    assertEquals("8 bits", attributes.get(JPEG_HEADER + "Data Precision"));
    assertEquals("Baseline", attributes.get(JPEG_HEADER + "Compression Type"));
    assertEquals("3", attributes.get(JPEG_HEADER + "Number of Components"));
    assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert",
            attributes.get(JPEG_HEADER + "Component 1"));
    assertEquals("Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert",
            attributes.get(JPEG_HEADER + "Component 2"));
    assertEquals("Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert",
            attributes.get(JPEG_HEADER + "Component 3"));
}
 
Example 2
Source File: ExtractImageMetadataTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
 public void testExtractBMP() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/16color-10x10.bmp", ExtractImageMetadata.SUCCESS, null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("10", attributes.get(BMP_HEADER+"Image Width"));
    assertEquals("10", attributes.get(BMP_HEADER+"Image Height"));
    assertEquals("4", attributes.get(BMP_HEADER+"Bits Per Pixel"));
    assertEquals("None", attributes.get(BMP_HEADER+"Compression"));
    assertEquals("0", attributes.get(BMP_HEADER+"X Pixels per Meter"));
    assertEquals("0", attributes.get(BMP_HEADER+"Y Pixels per Meter"));
    assertEquals("0", attributes.get(BMP_HEADER+"Palette Colour Count"));
    assertEquals("0", attributes.get(BMP_HEADER+"Important Colour Count"));
    assertEquals("1", attributes.get(BMP_HEADER+"Planes"));
    assertEquals("40", attributes.get(BMP_HEADER+"Header Size"));
}
 
Example 3
Source File: ExtractImageMetadataTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractLimitedAttributesBMP() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/16color-10x10.bmp", ExtractImageMetadata.SUCCESS, "5");
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("10", attributes.get(BMP_HEADER+"Image Width"));
    assertEquals("10", attributes.get(BMP_HEADER+"Image Height"));
    assertEquals("4", attributes.get(BMP_HEADER+"Bits Per Pixel"));
    assertEquals("1", attributes.get(BMP_HEADER+"Planes"));
    assertEquals("40", attributes.get(BMP_HEADER+"Header Size"));


    assertNull(attributes.get(BMP_HEADER + "Compression"));
    assertNull(attributes.get(BMP_HEADER + "X Pixels per Meter"));
    assertNull(attributes.get(BMP_HEADER + "Y Pixels per Meter"));
    assertNull(attributes.get(BMP_HEADER + "Palette Colour Count"));
    assertNull(attributes.get(BMP_HEADER + "Important Colour Count"));
}
 
Example 4
Source File: ExtractImageMetadataTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractJPG() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/simple.jpg", ExtractImageMetadata.SUCCESS,null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("800 pixels", attributes.get(JPEG_HEADER + "Image Width"));
    assertEquals("600 pixels", attributes.get(JPEG_HEADER + "Image Height"));
    assertEquals("8 bits", attributes.get(JPEG_HEADER + "Data Precision"));
    assertEquals("Baseline", attributes.get(JPEG_HEADER + "Compression Type"));
    assertEquals("3", attributes.get(JPEG_HEADER + "Number of Components"));
    assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert",
            attributes.get(JPEG_HEADER + "Component 1"));
    assertEquals("Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert",
            attributes.get(JPEG_HEADER + "Component 2"));
    assertEquals("Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert",
            attributes.get(JPEG_HEADER + "Component 3"));
}
 
Example 5
Source File: ExtractImageMetadataTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
 public void testExtractBMP() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/16color-10x10.bmp", ExtractImageMetadata.SUCCESS, null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("10", attributes.get(BMP_HEADER+"Image Width"));
    assertEquals("10", attributes.get(BMP_HEADER+"Image Height"));
    assertEquals("4", attributes.get(BMP_HEADER+"Bits Per Pixel"));
    assertEquals("None", attributes.get(BMP_HEADER+"Compression"));
    assertEquals("0", attributes.get(BMP_HEADER+"X Pixels per Meter"));
    assertEquals("0", attributes.get(BMP_HEADER+"Y Pixels per Meter"));
    assertEquals("0", attributes.get(BMP_HEADER+"Palette Colour Count"));
    assertEquals("0", attributes.get(BMP_HEADER+"Important Colour Count"));
    assertEquals("1", attributes.get(BMP_HEADER+"Planes"));
    assertEquals("40", attributes.get(BMP_HEADER+"Header Size"));
}
 
Example 6
Source File: ExtractImageMetadataTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractLimitedAttributesBMP() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/16color-10x10.bmp", ExtractImageMetadata.SUCCESS, "5");
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("10", attributes.get(BMP_HEADER+"Image Width"));
    assertEquals("10", attributes.get(BMP_HEADER+"Image Height"));
    assertEquals("1", attributes.get(BMP_HEADER+"Planes"));
    assertEquals("40", attributes.get(BMP_HEADER+"Header Size"));


    assertNull(attributes.get(BMP_HEADER + "Compression"));
    assertNull(attributes.get(BMP_HEADER + "X Pixels per Meter"));
    assertNull(attributes.get(BMP_HEADER + "Y Pixels per Meter"));
    assertNull(attributes.get(BMP_HEADER + "Palette Colour Count"));
    assertNull(attributes.get(BMP_HEADER + "Important Colour Count"));
}
 
Example 7
Source File: ExtractImageMetadataTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtractGIF() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow(
            "src/test/resources/photoshop-8x12-32colors-alpha.gif", ExtractImageMetadata.SUCCESS,null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("8", attributes.get(GIF_HEADER + "Image Width"));
    assertEquals("12", attributes.get(GIF_HEADER + "Image Height"));
    assertEquals("true", attributes.get(GIF_HEADER + "Has Global Color Table"));
    assertEquals("32", attributes.get(GIF_HEADER + "Color Table Size"));
    assertEquals("8", attributes.get(GIF_HEADER + "Transparent Color Index"));
    assertEquals("89a", attributes.get(GIF_HEADER + "GIF Format Version"));
    assertEquals("5", attributes.get(GIF_HEADER + "Bits per Pixel"));
    assertEquals("false", attributes.get(GIF_HEADER + "Is Color Table Sorted"));
}
 
Example 8
Source File: ExtractImageMetadataTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
 public void testExtractPNG() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/mspaint-8x10.png", ExtractImageMetadata.SUCCESS, null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("8", attributes.get(PNG_HEADER + "IHDR.Image Width"));
    assertEquals("12", attributes.get(PNG_HEADER + "IHDR.Image Height"));
    assertEquals("0.45455", attributes.get(PNG_HEADER + "gAMA.Image Gamma"));
    assertEquals("Deflate", attributes.get(PNG_HEADER + "IHDR.Compression Type"));
    assertEquals("No Interlace", attributes.get(PNG_HEADER + "IHDR.Interlace Method"));
    assertEquals("Perceptual", attributes.get(PNG_HEADER + "sRGB.sRGB Rendering Intent"));
    assertEquals("Adaptive", attributes.get(PNG_HEADER + "IHDR.Filter Method"));
    assertEquals("8", attributes.get(PNG_HEADER + "IHDR.Bits Per Sample"));
    assertEquals("True Color", attributes.get(PNG_HEADER + "IHDR.Color Type"));
}
 
Example 9
Source File: QuerySolrIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrievalOfFullResults() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "2");
    runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS);

    runner.enqueue(new byte[0]);
    runner.run();
    runner.assertTransferCount(QuerySolr.RESULTS, 5);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 1);
    runner.assertTransferCount(QuerySolr.STATS, 0);
    runner.assertTransferCount(QuerySolr.FACETS, 0);

    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(QuerySolr.RESULTS);
    Integer documentCounter = 0;
    Integer startParam = 0;

    for (MockFlowFile flowFile : flowFiles) {
        Map<String,String> attributes = flowFile.getAttributes();
        assertEquals(attributes.get(QuerySolr.ATTRIBUTE_SOLR_START), startParam.toString());
        startParam += 2;

        StringBuffer expectedXml = new StringBuffer()
                .append("<docs><doc boost=\"1.0\"><field name=\"id\">doc")
                .append(documentCounter++)
                .append("</field></doc><doc boost=\"1.0\"><field name=\"id\">doc")
                .append(documentCounter++)
                .append("</field></doc></docs>");
        assertThat(expectedXml.toString(), CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile))));
    }

    solrClient.close();
}
 
Example 10
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetrievalOfFullResults() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrClient(solrClient);

    runner.setProperty(QuerySolr.SOLR_PARAM_FIELD_LIST, "id");
    runner.setProperty(QuerySolr.SOLR_PARAM_SORT, "id asc");
    runner.setProperty(QuerySolr.SOLR_PARAM_ROWS, "2");
    runner.setProperty(QuerySolr.AMOUNT_DOCUMENTS_TO_RETURN, QuerySolr.RETURN_ALL_RESULTS);

    runner.enqueue(new byte[0]);
    runner.run();
    runner.assertTransferCount(QuerySolr.RESULTS, 5);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 1);
    runner.assertTransferCount(QuerySolr.STATS, 0);
    runner.assertTransferCount(QuerySolr.FACETS, 0);

    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(QuerySolr.RESULTS);
    Integer documentCounter = 0;
    Integer startParam = 0;

    for (MockFlowFile flowFile : flowFiles) {
        Map<String,String> attributes = flowFile.getAttributes();
        assertEquals(attributes.get(QuerySolr.ATTRIBUTE_SOLR_START), startParam.toString());
        startParam += 2;

        StringBuffer expectedXml = new StringBuffer()
                .append("<docs><doc><field name=\"id\">doc")
                .append(documentCounter++)
                .append("</field></doc><doc><field name=\"id\">doc")
                .append(documentCounter++)
                .append("</field></doc></docs>");
        assertThat(expectedXml.toString(), CompareMatcher.isIdenticalTo(new String(runner.getContentAsByteArray(flowFile))));
    }

    solrClient.close();
}
 
Example 11
Source File: ExtractImageMetadataTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtractGIF() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow(
            "src/test/resources/photoshop-8x12-32colors-alpha.gif", ExtractImageMetadata.SUCCESS,null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("8", attributes.get(GIF_HEADER + "Image Width"));
    assertEquals("12", attributes.get(GIF_HEADER + "Image Height"));
    assertEquals("true", attributes.get(GIF_HEADER + "Has Global Color Table"));
    assertEquals("32", attributes.get(GIF_HEADER + "Color Table Size"));
    assertEquals("8", attributes.get(GIF_CONTROL + "Transparent Color Index"));
    assertEquals("89a", attributes.get(GIF_HEADER + "GIF Format Version"));
    assertEquals("5", attributes.get(GIF_HEADER + "Bits per Pixel"));
    assertEquals("false", attributes.get(GIF_HEADER + "Is Color Table Sorted"));
}
 
Example 12
Source File: ExtractImageMetadataTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
 public void testExtractPNG() throws IOException {
    MockFlowFile flowFile = verifyTestRunnerFlow("src/test/resources/mspaint-8x10.png", ExtractImageMetadata.SUCCESS, null);
    Map<String, String> attributes = flowFile.getAttributes();

    assertEquals("8", attributes.get(PNG_HEADER + "IHDR.Image Width"));
    assertEquals("12", attributes.get(PNG_HEADER + "IHDR.Image Height"));
    assertEquals(String.format("0%s455", DecimalFormatSymbols.getInstance().getDecimalSeparator()), attributes.get(PNG_HEADER + "gAMA.Image Gamma"));
    assertEquals("Deflate", attributes.get(PNG_HEADER + "IHDR.Compression Type"));
    assertEquals("No Interlace", attributes.get(PNG_HEADER + "IHDR.Interlace Method"));
    assertEquals("Perceptual", attributes.get(PNG_HEADER + "sRGB.sRGB Rendering Intent"));
    assertEquals("Adaptive", attributes.get(PNG_HEADER + "IHDR.Filter Method"));
    assertEquals("8", attributes.get(PNG_HEADER + "IHDR.Bits Per Sample"));
    assertEquals("True Color", attributes.get(PNG_HEADER + "IHDR.Color Type"));
}
 
Example 13
Source File: TestQuerySolr.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testAttributes() throws IOException {
    SolrClient solrClient = createSolrClient();
    TestRunner runner = createRunnerWithSolrCloudClient(solrClient);

    runner.setProperty("facet", "true");
    runner.setProperty("stats", "true");

    runner.enqueue("");
    runner.run();

    runner.assertTransferCount(QuerySolr.RESULTS, 1);
    runner.assertTransferCount(QuerySolr.FACETS, 1);
    runner.assertTransferCount(QuerySolr.STATS, 1);
    runner.assertTransferCount(QuerySolr.ORIGINAL, 1);

    MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0);
    Map<String, String> attributes = flowFile.getAttributes();

    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_COLLECTION);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_QUERY);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_START);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_ROWS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile.assertAttributeExists(CoreAttributes.MIME_TYPE.key());

    assertEquals(SOLR_CONNECT, attributes.get(QuerySolr.ATTRIBUTE_SOLR_CONNECT));
    assertEquals(DEFAULT_SOLR_CORE, attributes.get(QuerySolr.ATTRIBUTE_SOLR_COLLECTION));

    assertEquals("q=*:*&qt=/select&start=0&rows=10&stats=true&facet=true", attributes.get(QuerySolr.ATTRIBUTE_SOLR_QUERY));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_STATUS));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_START));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_ROWS));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS));
    assertEquals(QuerySolr.MIME_TYPE_XML, attributes.get(CoreAttributes.MIME_TYPE.key()));

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0);
    attributes = flowFile.getAttributes();

    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_COLLECTION);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_QUERY);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_START);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_ROWS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile.assertAttributeExists(CoreAttributes.MIME_TYPE.key());

    assertEquals(SOLR_CONNECT, attributes.get(QuerySolr.ATTRIBUTE_SOLR_CONNECT));
    assertEquals(DEFAULT_SOLR_CORE, attributes.get(QuerySolr.ATTRIBUTE_SOLR_COLLECTION));

    assertEquals("q=*:*&qt=/select&start=0&rows=10&stats=true&facet=true", attributes.get(QuerySolr.ATTRIBUTE_SOLR_QUERY));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_STATUS));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_START));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_ROWS));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS));
    assertEquals(QuerySolr.MIME_TYPE_JSON, attributes.get(CoreAttributes.MIME_TYPE.key()));

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0);
    attributes = flowFile.getAttributes();

    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_COLLECTION);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_QUERY);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_START);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_ROWS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME);
    flowFile.assertAttributeExists(CoreAttributes.MIME_TYPE.key());

    assertEquals(SOLR_CONNECT, attributes.get(QuerySolr.ATTRIBUTE_SOLR_CONNECT));
    assertEquals(DEFAULT_SOLR_CORE, attributes.get(QuerySolr.ATTRIBUTE_SOLR_COLLECTION));

    assertEquals("q=*:*&qt=/select&start=0&rows=10&stats=true&facet=true", attributes.get(QuerySolr.ATTRIBUTE_SOLR_QUERY));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_STATUS));
    assertEquals("0", attributes.get(QuerySolr.ATTRIBUTE_SOLR_START));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_ROWS));
    assertEquals("10", attributes.get(QuerySolr.ATTRIBUTE_SOLR_NUMBER_RESULTS));
    assertEquals(QuerySolr.MIME_TYPE_JSON, attributes.get(CoreAttributes.MIME_TYPE.key()));

    flowFile = runner.getFlowFilesForRelationship(QuerySolr.ORIGINAL).get(0);
    attributes = flowFile.getAttributes();

    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_COLLECTION);
    flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_QUERY);

    assertEquals(SOLR_CONNECT, attributes.get(QuerySolr.ATTRIBUTE_SOLR_CONNECT));
    assertEquals(DEFAULT_SOLR_CORE, attributes.get(QuerySolr.ATTRIBUTE_SOLR_COLLECTION));

    solrClient.close();
}