Search in sources :

Example 26 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITPutSQS method testSimplePut.

@Test
public void testSimplePut() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new PutSQS());
    runner.setProperty(PutSNS.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(PutSQS.TIMEOUT, "30 secs");
    runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/100515378163/test-queue-000000000");
    Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid());
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "1.txt");
    runner.enqueue(Paths.get("src/test/resources/hello.txt"), attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutSQS.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 27 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITDeleteAzureBlobStorage method testDeleteBlob.

@Test
public void testDeleteBlob() throws StorageException, URISyntaxException, InvalidKeyException, IOException {
    String containerName = String.format("%s-%s", AzureTestUtil.TEST_CONTAINER_NAME_PREFIX, UUID.randomUUID());
    CloudBlobContainer container = AzureTestUtil.getContainer(containerName);
    container.createIfNotExists();
    uploadBlob(containerName, getFileFromResource(SAMPLE_FILE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(DeleteAzureBlobStorage.class);
    try {
        runner.setValidateExpressionUsage(true);
        runner.setProperty(AzureStorageUtils.ACCOUNT_NAME, AzureTestUtil.getAccountName());
        runner.setProperty(AzureStorageUtils.ACCOUNT_KEY, AzureTestUtil.getAccountKey());
        runner.setProperty(AzureStorageUtils.CONTAINER, containerName);
        runner.setProperty(DeleteAzureBlobStorage.BLOB, AzureTestUtil.TEST_BLOB_NAME);
        runner.enqueue(new byte[0]);
        runner.run(1);
        runner.assertAllFlowFilesTransferred(DeleteAzureBlobStorage.REL_SUCCESS);
    } finally {
        container.deleteIfExists();
    }
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) Test(org.junit.Test)

Example 28 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITFetchAzureBlobStorage method testFetchingBlob.

@Test
public void testFetchingBlob() throws InvalidKeyException, URISyntaxException, StorageException, IOException {
    String containerName = String.format("%s-%s", AzureTestUtil.TEST_CONTAINER_NAME_PREFIX, UUID.randomUUID());
    CloudBlobContainer container = AzureTestUtil.getContainer(containerName);
    container.createIfNotExists();
    CloudBlob blob = container.getBlockBlobReference(AzureTestUtil.TEST_BLOB_NAME);
    byte[] buf = "0123456789".getBytes();
    InputStream in = new ByteArrayInputStream(buf);
    blob.upload(in, 10);
    final TestRunner runner = TestRunners.newTestRunner(new FetchAzureBlobStorage());
    try {
        runner.setValidateExpressionUsage(true);
        runner.setProperty(AzureStorageUtils.ACCOUNT_NAME, AzureTestUtil.getAccountName());
        runner.setProperty(AzureStorageUtils.ACCOUNT_KEY, AzureTestUtil.getAccountKey());
        runner.setProperty(AzureStorageUtils.CONTAINER, containerName);
        runner.setProperty(FetchAzureBlobStorage.BLOB, "${azure.blobname}");
        final Map<String, String> attributes = new HashMap<>();
        attributes.put("azure.primaryUri", "https://" + AzureTestUtil.getAccountName() + ".blob.core.windows.net/" + containerName + "/" + AzureTestUtil.TEST_BLOB_NAME);
        attributes.put("azure.blobname", AzureTestUtil.TEST_BLOB_NAME);
        attributes.put("azure.blobtype", AzureStorageUtils.BLOCK);
        runner.enqueue(new byte[0], attributes);
        runner.run();
        runner.assertAllFlowFilesTransferred(AbstractAzureBlobProcessor.REL_SUCCESS, 1);
        List<MockFlowFile> flowFilesForRelationship = runner.getFlowFilesForRelationship(FetchAzureBlobStorage.REL_SUCCESS);
        for (MockFlowFile flowFile : flowFilesForRelationship) {
            flowFile.assertContentEquals("0123456789".getBytes());
            flowFile.assertAttributeEquals("azure.length", "10");
        }
    } finally {
        container.deleteIfExists();
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestRunner(org.apache.nifi.util.TestRunner) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) Test(org.junit.Test)

Example 29 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class TestConvertAvroToJSON method testMultipleAvroMessages.

@Test
public void testMultipleAvroMessages() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new ConvertAvroToJSON());
    final Schema schema = new Schema.Parser().parse(new File("src/test/resources/user.avsc"));
    runner.setProperty(ConvertAvroToJSON.CONTAINER_OPTIONS, ConvertAvroToJSON.CONTAINER_ARRAY);
    final GenericRecord user1 = new GenericData.Record(schema);
    user1.put("name", "Alyssa");
    user1.put("favorite_number", 256);
    final GenericRecord user2 = new GenericData.Record(schema);
    user2.put("name", "George");
    user2.put("favorite_number", 1024);
    user2.put("favorite_color", "red");
    final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema);
    final ByteArrayOutputStream out1 = AvroTestUtil.serializeAvroRecord(schema, datumWriter, user1, user2);
    runner.enqueue(out1.toByteArray());
    runner.run();
    runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0);
    out.assertContentEquals("[{\"name\": \"Alyssa\", \"favorite_number\": 256, \"favorite_color\": null},{\"name\": \"George\", \"favorite_number\": 1024, \"favorite_color\": \"red\"}]");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) File(java.io.File) MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Example 30 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class TestConvertAvroToJSON method testSingleAvroMessage_wrapSingleMessage_noContainer.

@Test
public void testSingleAvroMessage_wrapSingleMessage_noContainer() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new ConvertAvroToJSON());
    // Verify we do not wrap output for a single record if not configured to use a container
    runner.setProperty(ConvertAvroToJSON.CONTAINER_OPTIONS, ConvertAvroToJSON.CONTAINER_NONE);
    runner.setProperty(ConvertAvroToJSON.WRAP_SINGLE_RECORD, Boolean.toString(true));
    final Schema schema = new Schema.Parser().parse(new File("src/test/resources/user.avsc"));
    final GenericRecord user1 = new GenericData.Record(schema);
    user1.put("name", "Alyssa");
    user1.put("favorite_number", 256);
    final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema);
    final ByteArrayOutputStream out1 = AvroTestUtil.serializeAvroRecord(schema, datumWriter, user1);
    runner.enqueue(out1.toByteArray());
    runner.run();
    runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0);
    out.assertContentEquals("{\"name\": \"Alyssa\", \"favorite_number\": 256, \"favorite_color\": null}");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ByteArrayOutputStream(org.apache.nifi.stream.io.ByteArrayOutputStream) GenericRecord(org.apache.avro.generic.GenericRecord) File(java.io.File) MockFlowFile(org.apache.nifi.util.MockFlowFile) Test(org.junit.Test)

Aggregations

TestRunner (org.apache.nifi.util.TestRunner)1425 Test (org.junit.Test)1401 MockFlowFile (org.apache.nifi.util.MockFlowFile)753 HashMap (java.util.HashMap)304 File (java.io.File)138 ProcessContext (org.apache.nifi.processor.ProcessContext)56 ValidationResult (org.apache.nifi.components.ValidationResult)46 Connection (java.sql.Connection)44 Statement (java.sql.Statement)37 MockComponentLog (org.apache.nifi.util.MockComponentLog)35 TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)33 UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 ProcessSession (org.apache.nifi.processor.ProcessSession)31 ResultSet (java.sql.ResultSet)30 LogMessage (org.apache.nifi.util.LogMessage)29 Schema (org.apache.avro.Schema)28 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)27 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)27 Relationship (org.apache.nifi.processor.Relationship)27 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)27