Пример #1
0
  @Test
  public void testTCPSendDelimitedMessagesWithErrors() {
    sender.setErrorStart(3);
    sender.setErrorEnd(4);

    final String delimiter = "DD";
    runner.setProperty(PutSplunk.MESSAGE_DELIMITER, delimiter);
    runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.TCP_VALUE.getValue());

    // no delimiter at end
    final String success = "This is message 1DDThis is message 2DD";
    final String failure = "This is message 3DDThis is message 4";
    final String message = success + failure;

    runner.enqueue(message);
    runner.run(1);
    runner.assertTransferCount(PutSplunk.REL_SUCCESS, 1);
    runner.assertTransferCount(PutSplunk.REL_FAILURE, 1);

    // first two messages should went out success
    final MockFlowFile successFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0);
    successFlowFile.assertContentEquals(success);

    // second two messages should went to failure
    final MockFlowFile failureFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_FAILURE).get(0);
    failureFlowFile.assertContentEquals(failure);

    // should only have the first two messages
    Assert.assertEquals(2, sender.getMessages().size());
    Assert.assertEquals("This is message 1\n", sender.getMessages().get(0));
    Assert.assertEquals("This is message 2\n", sender.getMessages().get(1));
  }
Пример #2
0
  @Test
  public void testTCPSendDelimitedMessagesWithEL() {
    final String delimiter = "DD";
    runner.setProperty(PutSplunk.MESSAGE_DELIMITER, "${flow.file.delim}");
    runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.TCP_VALUE.getValue());

    // no delimiter at end
    final String message = "This is message 1DDThis is message 2DDThis is message 3";

    final Map<String, String> attrs = new HashMap<>();
    attrs.put("flow.file.delim", delimiter);

    runner.enqueue(message, attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1);

    final MockFlowFile mockFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0);
    mockFlowFile.assertContentEquals(message);

    Assert.assertEquals(3, sender.getMessages().size());
    Assert.assertEquals("This is message 1\n", sender.getMessages().get(0));
    Assert.assertEquals("This is message 2\n", sender.getMessages().get(1));
    Assert.assertEquals("This is message 3\n", sender.getMessages().get(2));
  }
Пример #3
0
  @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());
    }
  }
Пример #4
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();
  }
  @Test
  public void doTestFailureRoute() throws InitializationException, IOException {
    String message = "Malformed XML";

    testRunner.setProperty("Yes", ".*yes.*");

    testRunner.enqueue(message.getBytes());
    testRunner.run();
    testRunner.assertAllFlowFilesTransferred(UCSRouteMessageOnContent.REL_FAILURE, 1);
    final MockFlowFile out =
        testRunner.getFlowFilesForRelationship(UCSRouteMessageOnContent.REL_FAILURE).get(0);
    out.assertContentEquals(message);
  }
Пример #6
0
  @Test
  public void testUDPSendWholeFlowFile() {
    runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.UDP_VALUE.getValue());
    final String message = "This is one message, should send the whole FlowFile";

    runner.enqueue(message);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1);

    final MockFlowFile mockFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0);
    mockFlowFile.assertContentEquals(message);

    Assert.assertEquals(1, sender.getMessages().size());
    Assert.assertEquals(message, sender.getMessages().get(0));
  }
Пример #7
0
  @Test
  public void testCompletingPreviousBatchOnNextExecution() {
    runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.UDP_VALUE.getValue());

    final String message = "This is one message, should send the whole FlowFile";

    runner.enqueue(message);
    runner.run(2, false); // don't shutdown to prove that next onTrigger complete previous batch
    runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1);

    final MockFlowFile mockFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0);
    mockFlowFile.assertContentEquals(message);

    Assert.assertEquals(1, sender.getMessages().size());
    Assert.assertEquals(message, sender.getMessages().get(0));
  }
  @Test
  public void testNonXmlContent() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
    runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");

    final Map<String, String> attributes = new HashMap<>();
    runner.enqueue("not xml".getBytes(), attributes);

    runner.run();

    runner.assertAllFlowFilesTransferred(TransformXml.REL_FAILURE);
    final MockFlowFile original =
        runner.getFlowFilesForRelationship(TransformXml.REL_FAILURE).get(0);
    final String originalContent = new String(original.toByteArray(), StandardCharsets.UTF_8);

    original.assertContentEquals("not xml");
  }
  @Ignore("this test fails")
  @Test
  public void testTransformMath() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
    runner.setProperty("header", "Test for mod");
    runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");

    final Map<String, String> attributes = new HashMap<>();
    runner.enqueue(Paths.get("src/test/resources/TestTransformXml/math.xml"), attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
    final MockFlowFile transformed =
        runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
    final String transformedContent = new String(transformed.toByteArray(), StandardCharsets.UTF_8);

    transformed.assertContentEquals(Paths.get("src/test/resources/TestTransformXml/math.html"));
  }
Пример #10
0
  @Test
  public void testTCPSendDelimitedMessagesWithNewLineDelimiter() {
    final String delimiter = "\\n";
    runner.setProperty(PutSplunk.MESSAGE_DELIMITER, delimiter);
    runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.TCP_VALUE.getValue());

    final String message = "This is message 1\nThis is message 2\nThis is message 3";

    runner.enqueue(message);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1);

    final MockFlowFile mockFlowFile =
        runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0);
    mockFlowFile.assertContentEquals(message);

    Assert.assertEquals(3, sender.getMessages().size());
    Assert.assertEquals("This is message 1\n", sender.getMessages().get(0));
    Assert.assertEquals("This is message 2\n", sender.getMessages().get(1));
    Assert.assertEquals("This is message 3\n", sender.getMessages().get(2));
  }
  @Test
  public void doTestMatchCaseSensitiveRoute() throws InitializationException, IOException {
    String message =
        new MessageBuilder()
            .withConversationId("testC")
            .withSender("eafry")
            .withBody("This is the content of the test message with yes keyword")
            .addRecipient(new MessageBuilder.Recipient("491623342171", "SMS"))
            .buildSerializedMessageWrapper();

    testRunner.setProperty("Yes", ".*yes.*");
    testRunner.setProperty(UCSRouteMessageOnContent.CASE_SENSITIVE, UCSRouteMessageOnContent.TRUE);

    testRunner.enqueue(message.getBytes());
    testRunner.run();
    testRunner.assertAllFlowFilesTransferred("Yes", 1);
    final MockFlowFile out = testRunner.getFlowFilesForRelationship("Yes").get(0);
    out.assertAttributeExists(UCSRouteMessageOnContent.ROUTE_ATTRIBUTE_KEY);
    out.assertAttributeEquals(UCSRouteMessageOnContent.ROUTE_ATTRIBUTE_KEY, "Yes");
    out.assertContentEquals(message);
  }
Пример #12
0
  @Test
  public void testSendStreamToQueue() throws Exception {
    PutJMS putJms = new PutJMS();
    TestRunner putRunner = TestRunners.newTestRunner(putJms);
    putRunner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    putRunner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    putRunner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE);
    putRunner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    putRunner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);
    WrappedMessageProducer wrappedProducer =
        JmsFactory.createMessageProducer(putRunner.getProcessContext(), true);
    final Session jmsSession = wrappedProducer.getSession();
    final MessageProducer producer = wrappedProducer.getProducer();

    final StreamMessage message = jmsSession.createStreamMessage();
    message.writeBytes("Hello Stream".getBytes());

    producer.send(message);
    jmsSession.commit();

    GetJMSQueue getJmsQueue = new GetJMSQueue();
    TestRunner runner = TestRunners.newTestRunner(getJmsQueue);
    runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    runner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);

    runner.run();

    List<MockFlowFile> flowFiles =
        runner.getFlowFilesForRelationship(new Relationship.Builder().name("success").build());

    assertTrue(flowFiles.size() == 1);
    MockFlowFile successFlowFile = flowFiles.get(0);
    successFlowFile.assertContentEquals("Hello Stream");
    successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");

    producer.close();
    jmsSession.close();
  }
Пример #13
0
  @Ignore("this test fails")
  @Test
  public void testTransformCsv() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
    runner.setProperty(
        TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/tokens.xsl");
    runner.setProperty("uuid_0", "${uuid_0}");
    runner.setProperty("uuid_1", "${uuid_1}");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("uuid_0", "uuid_0");
    attributes.put("uuid_1", "uuid_1");

    StringBuilder builder = new StringBuilder();
    builder.append("<data>\n");

    InputStream in =
        new FileInputStream(new File("src/test/resources/TestTransformXml/tokens.csv"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    String line = null;
    while ((line = reader.readLine()) != null) {
      builder.append(line).append("\n");
    }
    builder.append("</data>");
    String data = builder.toString();
    runner.enqueue(data.getBytes(), attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
    final MockFlowFile transformed =
        runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
    final String transformedContent =
        new String(transformed.toByteArray(), StandardCharsets.ISO_8859_1);

    transformed.assertContentEquals(Paths.get("src/test/resources/TestTransformXml/tokens.xml"));
  }