Java Code Examples for com.couchbase.client.java.document.RawJsonDocument

The following examples show how to use com.couchbase.client.java.document.RawJsonDocument. These examples are extracted from open source projects. 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 Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExp() throws Exception {
    String docIdExp = "${'someProperty'}";
    String somePropertyValue = "doc-p";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(somePropertyValue, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(somePropertyValue, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    byte[] inFileData = "input FlowFile data".getBytes(StandardCharsets.UTF_8);
    Map<String, String> properties = new HashMap<>();
    properties.put("someProperty", somePropertyValue);
    testRunner.enqueue(inFileData, properties);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
}
 
Example 2
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExpWithEmptyFlowFile() throws Exception {
    String docIdExp = "doc-s";
    String docId = "doc-s";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(docId, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(docId, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    testRunner.enqueue(new byte[0]);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
}
 
Example 3
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExpWithInvalidExpression() throws Exception {
    String docIdExp = "${nonExistingFunction('doc-s')}";
    String docId = "doc-s";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(docId, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(docId, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);
    testRunner.enqueue(new byte[0]);

    try {
        testRunner.run();
        fail("Exception should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 4
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFlowFileContent() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    String content = "{\"key\":\"value\"}";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(inFileDataStr, content));
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0);
    orgFile.assertContentEquals(inFileDataStr);
}
 
Example 5
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 6
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseInvalidInputError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new RequestTooBigException();
    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, 0);
    testRunner.assertTransferCount(REL_FAILURE, 1);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
 
Example 7
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 8
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseTempFlowFileError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    // There is no suitable CouchbaseException for temp flowfile error, currently.
    CouchbaseException exception = new DurabilityException();
    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());
}
 
Example 9
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 10
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 11
Source Project: incubator-gobblin   Source File: CouchbaseWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test that a single Json document can be written successfully
 * @throws IOException
 * @throws DataConversionException
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test(groups={"timeout"})
public void testJsonDocumentWrite()
    throws IOException, DataConversionException, ExecutionException, InterruptedException {
  CouchbaseWriter writer = new CouchbaseWriter(_couchbaseEnvironment, ConfigFactory.empty());
  try {

    String key = "hello";
    String testContent = "hello world";
    HashMap<String, String> contentMap = new HashMap<>();
    contentMap.put("value", testContent);
    Gson gson = new Gson();
    String jsonString = gson.toJson(contentMap);
    RawJsonDocument jsonDocument = RawJsonDocument.create(key, jsonString);
    writer.write(jsonDocument, null).get();
    RawJsonDocument returnDoc = writer.getBucket().get(key, RawJsonDocument.class);

    Map<String, String> returnedMap = gson.fromJson(returnDoc.content(), Map.class);
    Assert.assertEquals(testContent, returnedMap.get("value"));
  } finally {
    writer.close();
  }
}
 
Example 12
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExp() throws Exception {
    String docIdExp = "${'someProperty'}";
    String somePropertyValue = "doc-p";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(somePropertyValue, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(somePropertyValue, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    byte[] inFileData = "input FlowFile data".getBytes(StandardCharsets.UTF_8);
    Map<String, String> properties = new HashMap<>();
    properties.put("someProperty", somePropertyValue);
    testRunner.enqueue(inFileData, properties);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
}
 
Example 13
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExpWithEmptyFlowFile() throws Exception {
    String docIdExp = "doc-s";
    String docId = "doc-s";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(docId, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(docId, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    testRunner.enqueue(new byte[0]);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
}
 
Example 14
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDocIdExpWithInvalidExpression() throws Exception {
    String docIdExp = "${nonExistingFunction('doc-s')}";
    String docId = "doc-s";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    when(bucket.get(docId, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(docId, content));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);
    testRunner.enqueue(new byte[0]);

    try {
        testRunner.run();
        fail("Exception should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 15
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInputFlowFileContent() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    String content = "{\"key\":\"value\"}";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(inFileDataStr, content));
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_ORIGINAL).get(0);
    orgFile.assertContentEquals(inFileDataStr);
}
 
Example 16
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPutToAttributeNoTargetAttribute() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    String content = "some-value";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenReturn(RawJsonDocument.create(inFileDataStr, content));
    setupMockBucket(bucket);

    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.setProperty(PUT_VALUE_TO_ATTRIBUTE, "${expressionReturningNoValue}");
    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 outFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0);
    outFile.assertContentEquals(inFileDataStr);
}
 
Example 17
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    Bucket bucket = mock(Bucket.class);
    String inFileDataStr = "doc-in";
    when(bucket.get(inFileDataStr, RawJsonDocument.class))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);


    byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 18
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCouchbaseInvalidInputError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new RequestTooBigException();
    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, 0);
    testRunner.assertTransferCount(REL_FAILURE, 1);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_FAILURE).get(0);
    orgFile.assertContentEquals(inputFileDataStr);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
 
Example 19
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 20
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 21
Source Project: nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 22
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 23
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDurabilityConstraint() throws Exception {
    String docId = "doc-a";

    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);

    Bucket bucket = mock(Bucket.class);
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.MASTER), eq(ReplicateTo.ONE)))
        .thenReturn(RawJsonDocument.create(docId, inFileData));
    setupMockBucket(bucket);

    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.PERSIST_TO, PersistTo.MASTER.toString());
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    testRunner.run();

    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.MASTER), eq(ReplicateTo.ONE));

    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);
}
 
Example 24
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDocIdExp() throws Exception {
    String docIdExp = "${'someProperty'}";
    String somePropertyValue = "doc-p";

    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(somePropertyValue, inFileData));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    Map<String, String> properties = new HashMap<>();
    properties.put("someProperty", somePropertyValue);
    testRunner.enqueue(inFileDataBytes, properties);
    testRunner.run();

    ArgumentCaptor<RawJsonDocument> capture = ArgumentCaptor.forClass(RawJsonDocument.class);
    verify(bucket, times(1)).upsert(capture.capture(), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
    assertEquals(somePropertyValue, capture.getValue().id());
    assertEquals(inFileData, capture.getValue().content());

    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);
}
 
Example 25
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidDocIdExp() throws Exception {
    String docIdExp = "${invalid_function(someProperty)}";
    String somePropertyValue = "doc-p";

    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(somePropertyValue, inFileData));
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    Map<String, String> properties = new HashMap<>();
    properties.put("someProperty", somePropertyValue);
    testRunner.enqueue(inFileDataBytes, properties);
    try {
        testRunner.run();
        fail("Exception should be thrown.");
    } catch (AssertionError e){
        Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 26
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInputFlowFileUuid() throws Exception {

    String uuid = "00029362-5106-40e8-b8a9-bf2cecfbc0d7";
    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(uuid, inFileData));
    setupMockBucket(bucket);

    Map<String, String> properties = new HashMap<>();
    properties.put(CoreAttributes.UUID.key(), uuid);
    testRunner.enqueue(inFileDataBytes, properties);
    testRunner.run();

    ArgumentCaptor<RawJsonDocument> capture = ArgumentCaptor.forClass(RawJsonDocument.class);
    verify(bucket, times(1)).upsert(capture.capture(), eq(PersistTo.NONE), eq(ReplicateTo.NONE));
    assertEquals(uuid, capture.getValue().id());
    assertEquals(inFileData, capture.getValue().content());

    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);
}
 
Example 27
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCouchbaseFailure() throws Exception {

    String docId = "doc-a";

    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.ONE)))
        .thenThrow(new ServiceNotAvailableException());
    setupMockBucket(bucket);

    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e){
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
    }

    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));

    testRunner.assertAllFlowFilesTransferred(REL_FAILURE);
    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}
 
Example 28
Source Project: localization_nifi   Source File: TestPutCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCouchbaseTempFlowFileError() throws Exception {

    String docId = "doc-a";

    String inFileData = "{\"key\":\"value\"}";
    byte[] inFileDataBytes = inFileData.getBytes(StandardCharsets.UTF_8);

    Bucket bucket = mock(Bucket.class);
    CouchbaseException exception = new DurabilityException();
    when(bucket.upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE)))
        .thenThrow(exception);
    setupMockBucket(bucket);

    testRunner.enqueue(inFileDataBytes);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
    testRunner.run();

    verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_RETRY, 1);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
    orgFile.assertContentEquals(inFileData);
    orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
}
 
Example 29
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testStaticDocId() throws Exception {
    String bucketName = "bucket-1";
    String docId = "doc-a";

    Bucket bucket = mock(Bucket.class);
    String content = "{\"key\":\"value\"}";
    int expiry = 100;
    long cas = 200L;
    when(bucket.get(docId, RawJsonDocument.class)).thenReturn(RawJsonDocument.create(docId, expiry, content, cas));
    setupMockBucket(bucket);

    testRunner.setProperty(BUCKET_NAME, bucketName);
    testRunner.setProperty(DOC_ID, docId);
    testRunner.enqueue(new byte[0]);
    testRunner.run();

    testRunner.assertTransferCount(REL_SUCCESS, 1);
    testRunner.assertTransferCount(REL_ORIGINAL, 1);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
    MockFlowFile outFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
    outFile.assertContentEquals(content);

    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));
}
 
Example 30
Source Project: localization_nifi   Source File: TestGetCouchbaseKey.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCouchbaseConfigurationError() throws Exception {
    String docIdExp = "doc-c";

    Bucket bucket = mock(Bucket.class);
    when(bucket.get(docIdExp, RawJsonDocument.class))
        .thenThrow(new AuthenticationException());
    setupMockBucket(bucket);

    testRunner.setProperty(DOC_ID, docIdExp);

    String inputFileDataStr = "input FlowFile data";
    byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
    testRunner.enqueue(inFileData);
    try {
        testRunner.run();
        fail("ProcessException should be thrown.");
    } catch (AssertionError e) {
        Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
        Assert.assertTrue(e.getCause().getCause().getClass().equals(AuthenticationException.class));
    }

    testRunner.assertTransferCount(REL_SUCCESS, 0);
    testRunner.assertTransferCount(REL_ORIGINAL, 0);
    testRunner.assertTransferCount(REL_RETRY, 0);
    testRunner.assertTransferCount(REL_FAILURE, 0);
}