@Test
  public void testContentsOfFileRetrieved() throws IOException {
    String key = "folder/1.txt";
    putTestFile(key, getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));

    final TestRunner runner = TestRunners.newTestRunner(new FetchS3Object());

    runner.setProperty(FetchS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(FetchS3Object.REGION, REGION);
    runner.setProperty(FetchS3Object.BUCKET, BUCKET_NAME);

    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", key);
    runner.enqueue(new byte[0], attrs);

    runner.run(1);

    runner.assertAllFlowFilesTransferred(FetchS3Object.REL_SUCCESS, 1);

    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS);
    final MockFlowFile out = ffs.iterator().next();

    final byte[] expectedBytes = Files.readAllBytes(getResourcePath(SAMPLE_FILE_RESOURCE_NAME));
    out.assertContentEquals(new String(expectedBytes));

    for (final Map.Entry<String, String> entry : out.getAttributes().entrySet()) {
      System.out.println(entry.getKey() + " : " + entry.getValue());
    }
  }
Exemple #2
0
  @Test
  public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception {
    JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination("cooQueue", false);
    JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
    sender.publish("Hey dude!".getBytes());
    TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(ConsumeJMS.DESTINATION, "cooQueue");
    runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
    runner.run(1, false);
    //
    final MockFlowFile successFF =
        runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
    assertNotNull(successFF);
    assertEquals("cooQueue", successFF.getAttributes().get(JmsHeaders.DESTINATION));
    successFF.assertContentEquals("Hey dude!".getBytes());

    ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
  }
Exemple #3
0
  @Test
  public void testSimplePutUsingCredentailsProviderService() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(new PutSQS());

    runner.setProperty(PutSQS.TIMEOUT, "30 secs");
    String queueUrl = "Add queue url here";
    runner.setProperty(PutSQS.QUEUE_URL, queueUrl);
    runner.setValidateExpressionUsage(false);
    final AWSCredentialsProviderControllerService serviceImpl =
        new AWSCredentialsProviderControllerService();

    runner.addControllerService("awsCredentialsProvider", serviceImpl);

    runner.setProperty(
        serviceImpl,
        AbstractAWSProcessor.CREDENTIALS_FILE,
        System.getProperty("user.home") + "/aws-credentials.properties");
    runner.enableControllerService(serviceImpl);

    runner.assertValid(serviceImpl);

    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "1.txt");
    runner.enqueue(Paths.get("src/test/resources/hello.txt"), attrs);
    runner.setProperty(PutSQS.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    runner.run(1);

    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutSQS.REL_SUCCESS);
    for (final MockFlowFile mff : flowFiles) {
      System.out.println(mff.getAttributes());
      System.out.println(new String(mff.toByteArray()));
    }
  }
  @Test
  public void testStringHashStringRangePutGetWithHashOnlyKeyFailure() {
    final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class);

    putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document");
    String document = "{\"name\":\"john\"}";
    putRunner.enqueue(document.getBytes());

    putRunner.run(1);

    putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles =
        putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
      System.out.println(flowFile.getAttributes());
      assertEquals(document, new String(flowFile.toByteArray()));
    }

    final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class);

    getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE);
    getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document");
    getRunner.enqueue(new byte[] {});

    getRunner.run(1);

    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);

    flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
      validateServiceExceptionAttribute(flowFile);
      assertEquals("", new String(flowFile.toByteArray()));
    }
  }
  @Test
  public void testNumberHashNumberRangePutGetDeleteGetSuccess() {
    final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class);

    putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, numberHashNumberRangeTableName);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashN");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeN");
    putRunner.setProperty(
        AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    putRunner.setProperty(
        AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "40");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "50");
    putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document");
    String document = "{\"40\":\"50\"}";
    putRunner.enqueue(document.getBytes());

    putRunner.run(1);

    putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1);

    List<MockFlowFile> flowFiles =
        putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
      assertEquals(document, new String(flowFile.toByteArray()));
    }

    final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class);

    getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE);
    getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, numberHashNumberRangeTableName);
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN");
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeN");
    getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40");
    getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "50");
    getRunner.setProperty(
        AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    getRunner.setProperty(
        AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document");
    getRunner.enqueue(new byte[] {});

    getRunner.run(1);

    getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1);

    flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
      assertEquals(document, new String(flowFile.toByteArray()));
    }

    final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class);

    deleteRunner.setProperty(DeleteDynamoDB.CREDENTIALS_FILE, CREDENTIALS_FILE);
    deleteRunner.setProperty(DeleteDynamoDB.REGION, REGION);
    deleteRunner.setProperty(DeleteDynamoDB.TABLE, numberHashNumberRangeTableName);
    deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_NAME, "hashN");
    deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_NAME, "rangeN");
    deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_VALUE, "40");
    deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_VALUE, "50");
    deleteRunner.setProperty(
        AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    deleteRunner.setProperty(
        AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    deleteRunner.enqueue(new byte[] {});

    deleteRunner.run(1);

    deleteRunner.assertAllFlowFilesTransferred(DeleteDynamoDB.REL_SUCCESS, 1);

    flowFiles = deleteRunner.getFlowFilesForRelationship(DeleteDynamoDB.REL_SUCCESS);
    for (MockFlowFile flowFile : flowFiles) {
      System.out.println(flowFile.getAttributes());
      assertEquals("", new String(flowFile.toByteArray()));
    }

    // Final check after delete
    final TestRunner getRunnerAfterDelete = TestRunners.newTestRunner(GetDynamoDB.class);

    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE);
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    getRunnerAfterDelete.setProperty(
        AbstractDynamoDBProcessor.TABLE, numberHashNumberRangeTableName);
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN");
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeN");
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40");
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "50");
    getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document");
    getRunnerAfterDelete.setProperty(
        AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    getRunnerAfterDelete.setProperty(
        AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE,
        AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER);
    getRunnerAfterDelete.enqueue(new byte[] {});

    getRunnerAfterDelete.run(1);
    getRunnerAfterDelete.assertAllFlowFilesTransferred(GetDynamoDB.REL_NOT_FOUND, 1);

    flowFiles = getRunnerAfterDelete.getFlowFilesForRelationship(GetDynamoDB.REL_NOT_FOUND);
    for (MockFlowFile flowFile : flowFiles) {
      String error = flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND);
      assertTrue(error.startsWith(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND_MESSAGE));
    }
  }