Search in sources :

Example 16 with MockFlowFile

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

the class TestExtractCCDAAttributes method runTests.

private void runTests(final String content, Map<String, String> expectedAttributes, final boolean skipValidation, final boolean prettyPrinting) throws IOException {
    runner.setProperty(ExtractCCDAAttributes.SKIP_VALIDATION, String.valueOf(skipValidation));
    runner.enqueue(content);
    runner.run();
    runner.assertAllFlowFilesTransferred(ExtractCCDAAttributes.REL_SUCCESS, 1);
    final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ExtractCCDAAttributes.REL_SUCCESS).get(0);
    for (final Map.Entry<String, String> entry : expectedAttributes.entrySet()) {
        flowFile.assertAttributeEquals(entry.getKey(), entry.getValue());
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with MockFlowFile

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

the class TestGetCouchbaseKey method testCouchbaseTempClusterError.

@Test
public void testCouchbaseTempClusterError() throws Exception {
    String docIdExp = "doc-c";
    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new BackpressureException();
    when(bucket.get(docIdExp, RawJsonDocument.class)).thenThrow(exception);
    setupMockBucket(bucket);
    testRunner.setProperty(DOC_ID, docIdExp);
    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) CouchbaseException(com.couchbase.client.core.CouchbaseException) Bucket(com.couchbase.client.java.Bucket) BackpressureException(com.couchbase.client.core.BackpressureException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 18 with MockFlowFile

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

the class TestGetCouchbaseKey method testDocumentNotFound.

@Test
public void testDocumentNotFound() throws Exception {
    String docIdExp = "doc-n";
    Bucket bucket = mock(Bucket.class);
    when(bucket.get(docIdExp, RawJsonDocument.class)).thenReturn(null);
    setupMockBucket(bucket);
    testRunner.setProperty(DOC_ID, docIdExp);
    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 1);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), DocumentDoesNotExistException.class.getName());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Bucket(com.couchbase.client.java.Bucket) DocumentDoesNotExistException(com.couchbase.client.java.error.DocumentDoesNotExistException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 19 with MockFlowFile

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

the class TestGetCouchbaseKey method testCouchbaseFatalError.

@Test
public void testCouchbaseFatalError() throws Exception {
    String docIdExp = "doc-c";
    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new NotConnectedException();
    when(bucket.get(docIdExp, RawJsonDocument.class)).thenThrow(exception);
    setupMockBucket(bucket);
    testRunner.setProperty(DOC_ID, docIdExp);
    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) CouchbaseException(com.couchbase.client.core.CouchbaseException) NotConnectedException(com.couchbase.client.core.state.NotConnectedException) Bucket(com.couchbase.client.java.Bucket) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with MockFlowFile

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

the class TestPutCouchbaseKey method testStaticDocId.

@Test
public void testStaticDocId() throws Exception {
    String bucketName = "bucket-1";
    String docId = "doc-a";
    int expiry = 100;
    long cas = 200L;
    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);
    Bucket bucket = mock(Bucket.class);
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE))).thenReturn(RawJsonDocument.create(docId, expiry, inFileData, cas));
    setupMockBucket(bucket);
    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(BUCKET_NAME, bucketName);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.run();
    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
    testRunner.assertAllFlowFilesTransferred(REL_SUCCESS);
    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(inFileData);
    outFile.assertAttributeEquals(CouchbaseAttributes.Cluster.key(), SERVICE_ID);
    outFile.assertAttributeEquals(CouchbaseAttributes.Bucket.key(), bucketName);
    outFile.assertAttributeEquals(CouchbaseAttributes.DocId.key(), docId);
    outFile.assertAttributeEquals(CouchbaseAttributes.Cas.key(), String.valueOf(cas));
    outFile.assertAttributeEquals(CouchbaseAttributes.Expiry.key(), String.valueOf(expiry));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) Bucket(com.couchbase.client.java.Bucket) Matchers.anyString(org.mockito.Matchers.anyString) RawJsonDocument(com.couchbase.client.java.document.RawJsonDocument) Test(org.junit.Test)

Aggregations

MockFlowFile (org.apache.nifi.util.MockFlowFile)1228 Test (org.junit.Test)1198 TestRunner (org.apache.nifi.util.TestRunner)725 HashMap (java.util.HashMap)279 File (java.io.File)155 Matchers.anyString (org.mockito.Matchers.anyString)59 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)48 FlowFile (org.apache.nifi.flowfile.FlowFile)42 ByteArrayInputStream (java.io.ByteArrayInputStream)41 ProcessContext (org.apache.nifi.processor.ProcessContext)37 InputStream (java.io.InputStream)34 Connection (java.sql.Connection)31 GenericRecord (org.apache.avro.generic.GenericRecord)31 Statement (java.sql.Statement)30 Schema (org.apache.avro.Schema)30 ArrayList (java.util.ArrayList)29 Map (java.util.Map)27 SQLException (java.sql.SQLException)25 DBCPService (org.apache.nifi.dbcp.DBCPService)25 GenericDatumWriter (org.apache.avro.generic.GenericDatumWriter)24