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());
}
}
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());
}
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());
}
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());
}
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));
}
Aggregations