Search in sources :

Example 86 with TestRunner

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

the class TestPutCloudWatchMetric method testValueLiteralDoubleInvalid.

@Test
public void testValueLiteralDoubleInvalid() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.VALUE, "nan");
    runner.assertNotValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 87 with TestRunner

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

the class TestPutCloudWatchMetric method testMissingBothValueAndStatisticSetInvalid.

@Test
public void testMissingBothValueAndStatisticSetInvalid() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.assertNotValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 88 with TestRunner

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

the class TestPutCloudWatchMetric method testDimensions.

@Test
public void testDimensions() throws Exception {
    MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
    final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
    runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
    runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
    runner.setProperty(PutCloudWatchMetric.VALUE, "1.0");
    runner.setProperty(PutCloudWatchMetric.UNIT, "Count");
    runner.setProperty(PutCloudWatchMetric.TIMESTAMP, "1476296132575");
    runner.setProperty(new PropertyDescriptor.Builder().dynamic(true).name("dim1").build(), "${metric.dim1}");
    runner.setProperty(new PropertyDescriptor.Builder().dynamic(true).name("dim2").build(), "val2");
    runner.assertValid();
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("metric.dim1", "1");
    runner.enqueue(new byte[] {}, attributes);
    runner.run();
    runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1);
    Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount);
    Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace);
    MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0);
    Assert.assertEquals("TestMetric", datum.getMetricName());
    Assert.assertEquals(1d, datum.getValue(), 0.0001d);
    List<Dimension> dimensions = datum.getDimensions();
    Collections.sort(dimensions, (d1, d2) -> d1.getName().compareTo(d2.getName()));
    Assert.assertEquals(2, dimensions.size());
    Assert.assertEquals("dim1", dimensions.get(0).getName());
    Assert.assertEquals("1", dimensions.get(0).getValue());
    Assert.assertEquals("dim2", dimensions.get(1).getName());
    Assert.assertEquals("val2", dimensions.get(1).getValue());
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Test(org.junit.Test)

Example 89 with TestRunner

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

the class TestCredentialsProviderFactory method testAssumeRoleInvalidProxyPort.

@Test
public void testAssumeRoleInvalidProxyPort() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties");
    runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_HOST, "proxy.company.com");
    runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_PORT, "notIntPort");
    runner.assertNotValid();
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 90 with TestRunner

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

the class TestCredentialsProviderFactory method testAssumeRoleCredentials.

@Test
public void testAssumeRoleCredentials() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
    runner.setProperty(CredentialPropertyDescriptors.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties");
    runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_ARN, "BogusArn");
    runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_NAME, "BogusSession");
    runner.assertValid();
    Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
    final CredentialsProviderFactory factory = new CredentialsProviderFactory();
    final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
    Assert.assertNotNull(credentialsProvider);
    assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, credentialsProvider.getClass());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) TestRunner(org.apache.nifi.util.TestRunner) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

TestRunner (org.apache.nifi.util.TestRunner)1337 Test (org.junit.Test)1315 MockFlowFile (org.apache.nifi.util.MockFlowFile)741 HashMap (java.util.HashMap)297 File (java.io.File)137 ProcessContext (org.apache.nifi.processor.ProcessContext)56 Connection (java.sql.Connection)44 Statement (java.sql.Statement)37 UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 ProcessSession (org.apache.nifi.processor.ProcessSession)31 ResultSet (java.sql.ResultSet)30 Schema (org.apache.avro.Schema)28 Relationship (org.apache.nifi.processor.Relationship)27 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)27 ByteArrayInputStream (java.io.ByteArrayInputStream)26 MockProcessContext (org.apache.nifi.util.MockProcessContext)25 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)24 Ignore (org.junit.Ignore)24 InputStream (java.io.InputStream)22 PutFlowFile (org.apache.nifi.hbase.put.PutFlowFile)22