Java Code Examples for org.apache.nifi.util.TestRunner#assertNotValid()
The following examples show how to use
org.apache.nifi.util.TestRunner#assertNotValid() .
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 File: TestPutSolrContentStream.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testJAASClientAppNameValidation() { final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class); runner.setProperty(PutSolrContentStream.SOLR_TYPE, PutSolrContentStream.SOLR_TYPE_STANDARD.getValue()); runner.setProperty(PutSolrContentStream.SOLR_LOCATION, "http://localhost:8443/solr"); runner.assertValid(); // clear the jaas config system property if it was set final String jaasConfig = System.getProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP); if (!StringUtils.isEmpty(jaasConfig)) { System.clearProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP); } // should be invalid if we have a client name but not config file runner.setProperty(PutSolrContentStream.JAAS_CLIENT_APP_NAME, "Client"); runner.assertNotValid(); // should be invalid if we have a client name that is not in the config file final File jaasConfigFile = new File("src/test/resources/jaas-client.conf"); System.setProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP, jaasConfigFile.getAbsolutePath()); runner.assertNotValid(); // should be valid now that the name matches up with the config file runner.setProperty(PutSolrContentStream.JAAS_CLIENT_APP_NAME, "SolrJClient"); runner.assertValid(); }
Example 2
Source File: TestJSONToAvroProcessor.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testEmptyContent() throws IOException { TestRunner runner = TestRunners.newTestRunner(ConvertJSONToAvro.class); runner.assertNotValid(); runner.setProperty(ConvertJSONToAvro.SCHEMA, SCHEMA.toString()); runner.assertValid(); runner.enqueue(streamFor("")); runner.run(); long converted = runner.getCounterValue("Converted records"); long errors = runner.getCounterValue("Conversion errors"); Assert.assertEquals("Should convert 0 rows", 0, converted); Assert.assertEquals("Should reject 0 row", 0, errors); runner.assertTransferCount("success", 0); runner.assertTransferCount("failure", 1); runner.assertTransferCount("incompatible", 0); MockFlowFile incompatible = runner.getFlowFilesForRelationship("failure").get(0); Assert.assertEquals("Should set an error message", "No incoming records", incompatible.getAttribute("errors")); }
Example 3
Source File: TestRouteText.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testSatisfiesExpression() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new RouteText()); runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.SATISFIES_EXPRESSION); runner.setProperty("empty", "${incomplete expression"); runner.assertNotValid(); runner.setProperty("empty", "${line:isEmpty()}"); runner.setProperty("third-line", "${lineNo:equals(3)}"); runner.setProperty("second-field-you", "${line:getDelimitedField(2):trim():equals('you')}"); runner.enqueue("hello\n\ngood-bye, you\n \t\t\n"); runner.run(); runner.assertTransferCount("empty", 1); runner.assertTransferCount("third-line", 1); runner.assertTransferCount("second-field-you", 1); runner.assertTransferCount("unmatched", 1); runner.assertTransferCount("original", 1); runner.getFlowFilesForRelationship("empty").get(0).assertContentEquals("\n \t\t\n"); runner.getFlowFilesForRelationship("third-line").get(0).assertContentEquals("good-bye, you\n"); runner.getFlowFilesForRelationship("second-field-you").get(0).assertContentEquals("good-bye, you\n"); }
Example 4
Source File: TestGetTwitter.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testLocationValidatorWithEqualLatitudes() { final TestRunner runner = TestRunners.newTestRunner(GetTwitter.class); runner.setProperty(GetTwitter.ENDPOINT, GetTwitter.ENDPOINT_FILTER); runner.setProperty(GetTwitter.MAX_CLIENT_ERROR_RETRIES, "5"); runner.setProperty(GetTwitter.CONSUMER_KEY, "consumerKey"); runner.setProperty(GetTwitter.CONSUMER_SECRET, "consumerSecret"); runner.setProperty(GetTwitter.ACCESS_TOKEN, "accessToken"); runner.setProperty(GetTwitter.ACCESS_TOKEN_SECRET, "accessTokenSecret"); runner.setProperty(GetTwitter.LOCATIONS, "-122.75,36.8,-121.75,37.8,-74,40,-73,40"); runner.assertNotValid(); }
Example 5
Source File: TestPutSolrRecord.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSolrTypeCloudShouldRequireCollection() throws InitializationException { final TestRunner runner = TestRunners.newTestRunner(PutSolrRecord.class); MockRecordParser recordParser = new MockRecordParser(); recordParser.addRecord(1, "Abhinav","R",8,"Chemistry","term1", 98); runner.addControllerService("parser", recordParser); runner.enableControllerService(recordParser); runner.setProperty(PutSolrRecord.RECORD_READER, "parser"); runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_CLOUD.getValue()); runner.setProperty(SolrUtils.SOLR_LOCATION, "http://localhost:8443/solr"); runner.assertNotValid(); runner.setProperty(SolrUtils.COLLECTION, "someCollection1"); runner.assertValid(); }
Example 6
Source File: TestJoltTransformJSON.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testIncorrectJOLTSpec() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json"))); runner.setProperty(JoltTransformJSON.JOLT_SPEC, chainrSpec); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR); runner.assertNotValid(); }
Example 7
Source File: AWSCredentialsProviderControllerServiceTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test(expected = AssertionError.class) public void testKeysCredentialsProviderWithRoleAndNameAndSessionTimeoutLessThan900() throws Throwable { final TestRunner runner = TestRunners.newTestRunner(FetchS3Object.class); final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService(); runner.addControllerService("awsCredentialsProvider", serviceImpl); runner.setProperty(serviceImpl, AbstractAWSProcessor.ACCESS_KEY, "awsAccessKey"); runner.setProperty(serviceImpl, AbstractAWSProcessor.SECRET_KEY, "awsSecretKey"); runner.setProperty(serviceImpl, AWSCredentialsProviderControllerService.ASSUME_ROLE_ARN, "Role"); runner.setProperty(serviceImpl, AWSCredentialsProviderControllerService.ASSUME_ROLE_NAME, "RoleName"); runner.setProperty(serviceImpl, AWSCredentialsProviderControllerService.MAX_SESSION_TIME, "899"); runner.enableControllerService(serviceImpl); runner.assertNotValid(serviceImpl); }
Example 8
Source File: PutHDFSTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testPutFileWhenDirectoryUsesInvalidEL() throws IOException { // Refer to comment in the BeforeClass method for an explanation assumeTrue(isNotWindows()); PutHDFS proc = new TestablePutHDFS(kerberosProperties); TestRunner runner = TestRunners.newTestRunner(proc); // the validator should pick up the invalid EL runner.setProperty(PutHDFS.DIRECTORY, "target/data_${literal('testing'):foo()}"); runner.setProperty(PutHDFS.CONFLICT_RESOLUTION, "replace"); runner.assertNotValid(); }
Example 9
Source File: TestCredentialsProviderFactory.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testExplicitDefaultCredentialsExclusive() throws Throwable { final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class); runner.setProperty(CredentialPropertyDescriptors.USE_DEFAULT_CREDENTIALS, "true"); runner.setProperty(CredentialPropertyDescriptors.ACCESS_KEY, "BogusAccessKey"); runner.assertNotValid(); }
Example 10
Source File: TestCredentialsProviderFactory.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testAssumeRoleCredentialsInvalidSessionTime() 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.setProperty(CredentialPropertyDescriptors.MAX_SESSION_TIME, "10"); runner.assertNotValid(); }
Example 11
Source File: TestXMLRecordSetWriter.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testValidation() throws IOException, InitializationException { XMLRecordSetWriter writer = new XMLRecordSetWriter(); TestRunner runner = setup(writer); runner.setProperty(writer, XMLRecordSetWriter.ROOT_TAG_NAME, "root"); runner.setProperty(writer, XMLRecordSetWriter.RECORD_TAG_NAME, "record"); runner.setProperty(writer, XMLRecordSetWriter.ARRAY_WRAPPING, XMLRecordSetWriter.USE_PROPERTY_AS_WRAPPER); runner.assertNotValid(writer); runner.setProperty(writer, XMLRecordSetWriter.ARRAY_TAG_NAME, "array-tag-name"); runner.assertValid(writer); runner.enableControllerService(writer); runner.enqueue(""); String message = "Processor has 1 validation failures:\n" + "'xml_writer' validated against 'xml_writer' is invalid because Controller Service is not valid: " + "'array_tag_name' is invalid because if property 'array_wrapping' is defined as 'Use Property as Wrapper' " + "or 'Use Property for Elements' the property 'Array Tag Name' has to be set.\n"; try { runner.run(); } catch (AssertionError e) { Assert.assertEquals(message, e.getMessage()); } }
Example 12
Source File: TestDeleteHDFS.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testGlobDelete() throws Exception { Path glob = new Path("/data/for/2017/08/05/*"); int fileCount = 300; FileStatus[] fileStatuses = new FileStatus[fileCount]; for (int i = 0; i < fileCount; i++) { Path file = new Path("/data/for/2017/08/05/file" + i); FileStatus fileStatus = mock(FileStatus.class); when(fileStatus.getPath()).thenReturn(file); fileStatuses[i] = fileStatus; } when(mockFileSystem.exists(any(Path.class))).thenReturn(true); when(mockFileSystem.globStatus(any(Path.class))).thenReturn(fileStatuses); DeleteHDFS deleteHDFS = new TestableDeleteHDFS(kerberosProperties, mockFileSystem); TestRunner runner = TestRunners.newTestRunner(deleteHDFS); runner.setIncomingConnection(false); runner.assertNotValid(); runner.setProperty(DeleteHDFS.FILE_OR_DIRECTORY, glob.toString()); runner.assertValid(); runner.run(); runner.assertAllFlowFilesTransferred(DeleteHDFS.REL_SUCCESS); runner.assertTransferCount(DeleteHDFS.REL_SUCCESS, fileCount); List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(DeleteHDFS.REL_SUCCESS); for (int i = 0; i < fileCount; i++) { FlowFile flowFile = flowFiles.get(i); assertEquals("file" + i, flowFile.getAttribute("filename")); assertEquals("/data/for/2017/08/05", flowFile.getAttribute("path")); } }
Example 13
Source File: TestJoltTransformRecord.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testJoltSpecInvalidEL() { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformRecord()); final String spec = "${joltSpec:nonExistingFunction()}"; runner.setProperty(JoltTransformRecord.JOLT_SPEC, spec); runner.enqueue(new byte[0]); runner.assertNotValid(); }
Example 14
Source File: TestUpdateAttribute.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testBasicState() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY); runner.setProperty("count", "${getStateValue('count'):plus(1)}"); runner.setProperty("sum", "${getStateValue('sum'):plus(${pencils})}"); runner.assertNotValid(); runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0"); runner.assertValid(); final Map<String, String> attributes2 = new HashMap<>(); attributes2.put("pencils", "2"); runner.enqueue(new byte[0],attributes2); runner.enqueue(new byte[0],attributes2); final Map<String, String> attributes3 = new HashMap<>(); attributes3.put("pencils", "3"); runner.enqueue(new byte[0], attributes3); runner.enqueue(new byte[0], attributes3); final Map<String, String> attributes5 = new HashMap<>(); attributes5.put("pencils", "5"); runner.enqueue(new byte[0], attributes5); runner.run(5); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 5); runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS).get(4).assertAttributeEquals("count", "5"); runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS).get(4).assertAttributeEquals("sum", "15"); }
Example 15
Source File: AWSCredentialsProviderControllerServiceTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testKeysCredentialsProviderWithRoleOnlyInvalid() throws Throwable { final TestRunner runner = TestRunners.newTestRunner(FetchS3Object.class); final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService(); runner.addControllerService("awsCredentialsProvider", serviceImpl); runner.setProperty(serviceImpl, AbstractAWSProcessor.ACCESS_KEY, "awsAccessKey"); runner.setProperty(serviceImpl, AbstractAWSProcessor.SECRET_KEY, "awsSecretKey"); runner.setProperty(serviceImpl, AWSCredentialsProviderControllerService.ASSUME_ROLE_ARN, "Role"); runner.assertNotValid(serviceImpl); }
Example 16
Source File: AWSCredentialsProviderControllerServiceTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testAccessKeyOnlyInvalid() throws Throwable { final TestRunner runner = TestRunners.newTestRunner(FetchS3Object.class); final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService(); runner.addControllerService("awsCredentialsProvider", serviceImpl); runner.setProperty(serviceImpl, AbstractAWSProcessor.ACCESS_KEY, "awsAccessKey"); runner.enableControllerService(serviceImpl); runner.assertNotValid(serviceImpl); }
Example 17
Source File: PutBigQueryBatchTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testMandatoryProjectId() throws Exception { final TestRunner runner = buildNewRunner(getProcessor()); addRequiredPropertiesToRunner(runner); runner.assertValid(); runner.removeProperty(PutBigQueryBatch.PROJECT_ID); runner.assertNotValid(); }
Example 18
Source File: JMSConnectionFactoryProviderTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateNotValidForNonExistingLibPath() throws Exception { TestRunner runner = TestRunners.newTestRunner(mock(Processor.class)); JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider(); runner.addControllerService("cfProvider", cfProvider); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI, "myhost:1234"); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, "foo"); runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL, "org.apache.nifi.jms.testcflib.TestConnectionFactory"); runner.assertNotValid(cfProvider); }
Example 19
Source File: TestPutSolrContentStream.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testUsernamePasswordValidation() { final TestRunner runner = TestRunners.newTestRunner(PutSolrContentStream.class); runner.setProperty(SolrUtils.SOLR_TYPE, SolrUtils.SOLR_TYPE_STANDARD.getValue()); runner.setProperty(SolrUtils.SOLR_LOCATION, "http://localhost:8443/solr"); runner.assertValid(); runner.setProperty(SolrUtils.BASIC_USERNAME, "user1"); runner.assertNotValid(); runner.setProperty(SolrUtils.BASIC_PASSWORD, "password"); runner.assertValid(); runner.setProperty(SolrUtils.BASIC_USERNAME, ""); runner.assertNotValid(); runner.setProperty(SolrUtils.BASIC_USERNAME, "${solr.user}"); runner.assertNotValid(); runner.setVariable("solr.user", "solrRocks"); runner.assertValid(); runner.setProperty(SolrUtils.BASIC_PASSWORD, "${solr.password}"); runner.assertNotValid(); runner.setVariable("solr.password", "solrRocksPassword"); runner.assertValid(); }
Example 20
Source File: TestJoltTransformJSON.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testSpecIsNotSet() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR); runner.assertNotValid(); }