Java Code Examples for org.apache.nifi.util.TestRunner#removeProperty()
The following examples show how to use
org.apache.nifi.util.TestRunner#removeProperty() .
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: PutMongoIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testClientService() throws Exception { MongoDBClientService clientService = new MongoDBControllerService(); TestRunner runner = init(PutMongo.class); runner.addControllerService("clientService", clientService); runner.removeProperty(PutMongo.URI); runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI); runner.setProperty(PutMongo.CLIENT_SERVICE, "clientService"); runner.enableControllerService(clientService); runner.assertValid(); runner.enqueue("{ \"msg\": \"Hello, world\" }"); runner.run(); runner.assertTransferCount(PutMongo.REL_SUCCESS, 1); runner.assertTransferCount(PutMongo.REL_FAILURE, 0); }
Example 2
Source File: DeleteMongoIT.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testClientService() throws Exception { MongoDBClientService clientService = new MongoDBControllerService(); TestRunner runner = init(DeleteMongo.class); runner.addControllerService("clientService", clientService); runner.removeProperty(DeleteMongo.URI); runner.setProperty(DeleteMongo.DELETE_MODE, DeleteMongo.DELETE_MANY); runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI); runner.setProperty(DeleteMongo.CLIENT_SERVICE, "clientService"); runner.enableControllerService(clientService); runner.assertValid(); runner.enqueue("{}"); runner.run(); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); Assert.assertEquals(0, collection.count()); }
Example 3
Source File: TestPutSolrContentStream.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testBasicAuthAndKerberosCredentialServiceNotAllowedTogether() throws IOException, InitializationException { final SolrClient solrClient = createEmbeddedSolrClient(DEFAULT_SOLR_CORE); final TestableProcessor proc = new TestableProcessor(solrClient); final TestRunner runner = createDefaultTestRunner(proc); runner.assertValid(); runner.setProperty(SolrUtils.BASIC_USERNAME, "user1"); runner.setProperty(SolrUtils.BASIC_PASSWORD, "password"); runner.assertValid(); final String principal = "[email protected]"; final String keytab = "src/test/resources/foo.keytab"; final KerberosCredentialsService kerberosCredentialsService = new MockKerberosCredentialsService(principal, keytab); runner.addControllerService("kerb-credentials", kerberosCredentialsService); runner.enableControllerService(kerberosCredentialsService); runner.setProperty(SolrUtils.KERBEROS_CREDENTIALS_SERVICE, "kerb-credentials"); runner.assertNotValid(); runner.removeProperty(SolrUtils.BASIC_USERNAME); runner.removeProperty(SolrUtils.BASIC_PASSWORD); runner.assertValid(); proc.onScheduled(runner.getProcessContext()); final KerberosUser kerberosUser = proc.getMockKerberosKeytabUser(); Assert.assertNotNull(kerberosUser); Assert.assertEquals(principal, kerberosUser.getPrincipal()); Assert.assertEquals(keytab, ((KerberosKeytabUser)kerberosUser).getKeytabFile()); }
Example 4
Source File: TestPutSolrContentStream.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testBasicAuthAndKerberosPrincipalPasswordNotAllowedTogether() throws IOException, InitializationException { final SolrClient solrClient = createEmbeddedSolrClient(DEFAULT_SOLR_CORE); final TestableProcessor proc = new TestableProcessor(solrClient); final TestRunner runner = createDefaultTestRunner(proc); runner.assertValid(); runner.setProperty(SolrUtils.BASIC_USERNAME, "user1"); runner.setProperty(SolrUtils.BASIC_PASSWORD, "password"); runner.assertValid(); final String kerberosPrincipal = "[email protected]"; final String kerberosPassword = "nifi"; runner.setProperty(SolrUtils.KERBEROS_PRINCIPAL, kerberosPrincipal); runner.setProperty(SolrUtils.KERBEROS_PASSWORD, kerberosPassword); runner.assertNotValid(); runner.removeProperty(SolrUtils.BASIC_USERNAME); runner.removeProperty(SolrUtils.BASIC_PASSWORD); runner.assertValid(); proc.onScheduled(runner.getProcessContext()); final KerberosUser kerberosUser = proc.getMockKerberosKeytabUser(); Assert.assertNotNull(kerberosUser); Assert.assertEquals(kerberosPrincipal, kerberosUser.getPrincipal()); }
Example 5
Source File: TestPutSolrContentStream.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testKerberosPrincipalPasswordAndKerberosCredentialServiceNotAllowedTogether() throws IOException, InitializationException { final SolrClient solrClient = createEmbeddedSolrClient(DEFAULT_SOLR_CORE); final TestableProcessor proc = new TestableProcessor(solrClient); final TestRunner runner = createDefaultTestRunner(proc); runner.assertValid(); final String kerberosPrincipal = "[email protected]"; final String kerberosPassword = "nifi"; runner.setProperty(SolrUtils.KERBEROS_PRINCIPAL, kerberosPrincipal); runner.setProperty(SolrUtils.KERBEROS_PASSWORD, kerberosPassword); final String principal = "[email protected]"; final String keytab = "src/test/resources/foo.keytab"; final KerberosCredentialsService kerberosCredentialsService = new MockKerberosCredentialsService(principal, keytab); runner.addControllerService("kerb-credentials", kerberosCredentialsService); runner.enableControllerService(kerberosCredentialsService); runner.setProperty(SolrUtils.KERBEROS_CREDENTIALS_SERVICE, "kerb-credentials"); runner.assertNotValid(); runner.removeProperty(SolrUtils.KERBEROS_PRINCIPAL); runner.removeProperty(SolrUtils.KERBEROS_PASSWORD); runner.assertValid(); proc.onScheduled(runner.getProcessContext()); final KerberosUser kerberosUser = proc.getMockKerberosKeytabUser(); Assert.assertNotNull(kerberosUser); Assert.assertEquals(principal, kerberosUser.getPrincipal()); Assert.assertEquals(keytab, ((KerberosKeytabUser)kerberosUser).getKeytabFile()); }
Example 6
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 7
Source File: PutMongoTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testQueryKeyValidation() { TestRunner runner = TestRunners.newTestRunner(PutMongo.class); runner.setProperty(PutMongo.URI, "mongodb://localhost:27017"); runner.setProperty(PutMongo.DATABASE_NAME, "demo"); runner.setProperty(PutMongo.COLLECTION_NAME, "messages"); runner.setProperty(PutMongo.MODE, PutMongo.MODE_INSERT); runner.assertValid(); runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE); runner.setProperty(PutMongo.UPDATE_QUERY, "{}"); runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "test"); runner.assertNotValid(); Collection<ValidationResult> results = null; if (runner.getProcessContext() instanceof MockProcessContext) { results = ((MockProcessContext) runner.getProcessContext()).validate(); } Assert.assertNotNull(results); Assert.assertEquals(1, results.size()); Iterator<ValidationResult> it = results.iterator(); Assert.assertTrue(it.next().toString().endsWith("Both update query key and update query cannot be set at the same time.")); runner.removeProperty(PutMongo.UPDATE_QUERY); runner.removeProperty(PutMongo.UPDATE_QUERY_KEY); runner.assertNotValid(); results = null; if (runner.getProcessContext() instanceof MockProcessContext) { results = ((MockProcessContext) runner.getProcessContext()).validate(); } Assert.assertNotNull(results); Assert.assertEquals(1, results.size()); it = results.iterator(); Assert.assertTrue(it.next().toString().endsWith("Either the update query key or the update query field must be set.")); }
Example 8
Source File: PutMongoIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testNoQueryAndNoUpdateKey() { TestRunner runner = init(PutMongo.class); runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE); runner.removeProperty(PutMongo.UPDATE_QUERY); runner.setProperty(PutMongo.UPDATE_QUERY_KEY, ""); runner.assertNotValid(); }
Example 9
Source File: FetchGCSObjectTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testBlobIdWithGeneration() throws Exception { reset(storage); final TestRunner runner = buildNewRunner(getProcessor()); addRequiredPropertiesToRunner(runner); runner.removeProperty(FetchGCSObject.KEY); runner.removeProperty(FetchGCSObject.BUCKET); runner.setProperty(FetchGCSObject.GENERATION, String.valueOf(GENERATION)); runner.assertValid(); final Blob blob = mock(Blob.class); when(storage.get(any(BlobId.class))).thenReturn(blob); when(storage.reader(any(BlobId.class), any(Storage.BlobSourceOption.class))).thenReturn(new MockReadChannel(CONTENT)); runner.enqueue("", ImmutableMap.of( BUCKET_ATTR, BUCKET, CoreAttributes.FILENAME.key(), KEY )); runner.run(); ArgumentCaptor<BlobId> blobIdArgumentCaptor = ArgumentCaptor.forClass(BlobId.class); ArgumentCaptor<Storage.BlobSourceOption> blobSourceOptionArgumentCaptor = ArgumentCaptor.forClass(Storage.BlobSourceOption.class); verify(storage).get(blobIdArgumentCaptor.capture()); verify(storage).reader(any(BlobId.class), blobSourceOptionArgumentCaptor.capture()); final BlobId blobId = blobIdArgumentCaptor.getValue(); assertEquals( BUCKET, blobId.getBucket() ); assertEquals( KEY, blobId.getName() ); assertEquals( GENERATION, blobId.getGeneration() ); final Set<Storage.BlobSourceOption> blobSourceOptions = ImmutableSet.copyOf(blobSourceOptionArgumentCaptor.getAllValues()); assertTrue(blobSourceOptions.contains(Storage.BlobSourceOption.generationMatch())); assertEquals( 1, blobSourceOptions.size() ); }
Example 10
Source File: GetMongoTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testValidators() { TestRunner runner = TestRunners.newTestRunner(GetMongo.class); Collection<ValidationResult> results; ProcessContext pc; // missing uri, db, collection runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(3, results.size()); Iterator<ValidationResult> it = results.iterator(); Assert.assertTrue(it.next().toString().contains("is invalid because Mongo URI is required")); Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // missing query - is ok runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME); runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(0, results.size()); // invalid query runner.setProperty(GetMongo.QUERY, "{a: x,y,z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().matches("'Query' .* is invalid because org.bson.json.JsonParseException")); // invalid projection runner.setProperty(GetMongo.QUERY, "{a: 1}"); runner.setProperty(GetMongo.PROJECTION, "{a: x,y,z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().matches("'Projection' .* is invalid because org.bson.json.JsonParseException")); // invalid sort runner.removeProperty(GetMongo.PROJECTION); runner.setProperty(GetMongo.SORT, "{a: x,y,z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().matches("'Sort' .* is invalid because org.bson.json.JsonParseException")); }
Example 11
Source File: ProtobufEncoderTest.java From nifi-protobuf-processor with MIT License | 4 votes |
/** * Test encoding using a processor-wide schema and switches between flowfile schema and processor schema * @throws Exception */ @Test public void onPropertyModified() throws Exception { TestRunner runner = TestRunners.newTestRunner(new ProtobufEncoder()); HashMap<String, String> addressBookProperties = new HashMap<>(); addressBookProperties.put("protobuf.messageType", "AddressBook"); /* First try to decode using a schema set in a processor property */ runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath()); runner.assertValid(); runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS); // Finally check the content MockFlowFile result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0); result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data")); /* Then try to remove the schema from the processor property and see if it still parse */ runner.clearTransferState(); runner.removeProperty(runner.getProcessor().getPropertyDescriptor("protobuf.schemaPath")); Assert.assertFalse("The schema property should now be null", runner.getProcessContext().getProperty("protobuf.schemaPath").isSet()); runner.assertValid(); runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.INVALID_SCHEMA); /* Finally add the property again to see if it works again */ runner.clearTransferState(); runner.setProperty("protobuf.schemaPath", ProtobufEncoderTest.class.getResource("/schemas/AddressBook.desc").getPath()); runner.assertValid(); runner.enqueue(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.json"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS); // Finally check the content result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0); result.assertContentEquals(ProtobufEncoderTest.class.getResourceAsStream("/data/AddressBook_basic.data")); }
Example 12
Source File: ProtobufDecoderTest.java From nifi-protobuf-processor with MIT License | 4 votes |
/** * Test decoding using a processor-wide schema and switches between flowfile schema and processor schema * @throws Exception */ @Test public void onPropertyModified() throws Exception { TestRunner runner = TestRunners.newTestRunner(new ProtobufDecoder()); HashMap<String, String> addressBookProperties = new HashMap<>(); addressBookProperties.put("protobuf.messageType", "AddressBook"); /* First try to decode using a schema set in a processor property */ runner.setProperty("protobuf.schemaPath", ProtobufDecoderTest.class.getResource("/schemas/AddressBook.desc").getPath()); runner.assertValid(); runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS); // Finally check the content MockFlowFile result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0); ObjectMapper mapper = new ObjectMapper(); JsonNode expected = mapper.readTree(this.getClass().getResourceAsStream("/data/AddressBook_basic.json")); JsonNode given = mapper.readTree(runner.getContentAsByteArray(result)); Assert.assertEquals("The parsing result of AddressBook_basic.data is not as expected", expected, given); /* Then try to remove the schema from the processor property and see if it still parse */ runner.clearTransferState(); runner.removeProperty(runner.getProcessor().getPropertyDescriptor("protobuf.schemaPath")); Assert.assertFalse("The schema property should now be null", runner.getProcessContext().getProperty("protobuf.schemaPath").isSet()); runner.assertValid(); runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.INVALID_SCHEMA); /* Finally add the property again to see if it works again */ runner.clearTransferState(); runner.setProperty("protobuf.schemaPath", ProtobufDecoderTest.class.getResource("/schemas/AddressBook.desc").getPath()); runner.assertValid(); runner.enqueue(ProtobufDecoderTest.class.getResourceAsStream("/data/AddressBook_basic.data"), addressBookProperties); runner.run(1); // Check if the flowfile has been successfully processed runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(ProtobufDecoder.SUCCESS); // Finally check the content result = runner.getFlowFilesForRelationship(ProtobufDecoder.SUCCESS).get(0); expected = mapper.readTree(this.getClass().getResourceAsStream("/data/AddressBook_basic.json")); given = mapper.readTree(runner.getContentAsByteArray(result)); Assert.assertEquals("The parsing result of AddressBook_basic.data is not as expected", expected, given); }
Example 13
Source File: HadoopDBCPConnectionPoolTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testCustomValidateWhenAllowExplicitKeytab() throws InitializationException { final Processor testProcessor = new TestProcessor(); final TestRunner runner = TestRunners.newTestRunner(testProcessor, kerberosContext); // Configure minimum required properties.. final HadoopDBCPConnectionPool hadoopDBCPService = new TestableHadoopDBCPConnectionPool(true); runner.addControllerService("hadoop-dbcp-service", hadoopDBCPService); runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.DATABASE_URL, "jdbc:phoenix:zk-host1,zk-host2:2181:/hbase"); runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.DB_DRIVERNAME, "org.apache.phoenix.jdbc.PhoenixDriver"); runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.DB_DRIVER_LOCATION, "target"); // Security is not enabled yet since no conf files provided, so should be valid runner.assertValid(hadoopDBCPService); // Enable security, should be invalid until some form of kerberos credentials are provided runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.HADOOP_CONFIGURATION_RESOURCES, "src/test/resources/core-site-security.xml"); runner.assertNotValid(hadoopDBCPService); // Configure principal and keytab, should be valid runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosPrincipal(), "[email protected]"); runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosKeytab(), "src/test/resources/fake.keytab"); runner.assertValid(hadoopDBCPService); // Configure password, should become invalid runner.setProperty(hadoopDBCPService, kerberosProps.getKerberosPassword(), "password"); runner.assertNotValid(hadoopDBCPService); // Remove keytab property, should become valid runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosKeytab()); runner.assertValid(hadoopDBCPService); // Configure a KeberosCredentialService, should become invalid final KerberosCredentialsService kerberosCredentialsService = new MockKerberosCredentialsService( "[email protected]", "src/test/resources/fake.keytab"); runner.addControllerService("kerb-credentials", kerberosCredentialsService); runner.enableControllerService(kerberosCredentialsService); runner.setProperty(hadoopDBCPService, HadoopDBCPConnectionPool.KERBEROS_CREDENTIALS_SERVICE, "kerb-credentials"); runner.assertNotValid(hadoopDBCPService); // Remove password property, still invalid runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosPassword()); runner.assertNotValid(hadoopDBCPService); // Remove principal property, only using keytab service, should become valid runner.removeProperty(hadoopDBCPService, kerberosProps.getKerberosPrincipal()); runner.assertValid(hadoopDBCPService); }
Example 14
Source File: FetchGCSObjectTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testBlobIdWithGeneration() throws Exception { reset(storage); final TestRunner runner = buildNewRunner(getProcessor()); addRequiredPropertiesToRunner(runner); runner.removeProperty(FetchGCSObject.KEY); runner.removeProperty(FetchGCSObject.BUCKET); runner.setProperty(FetchGCSObject.GENERATION, String.valueOf(GENERATION)); runner.assertValid(); final Blob blob = mock(Blob.class); when(storage.get(any(BlobId.class))).thenReturn(blob); when(storage.reader(any(BlobId.class), any(Storage.BlobSourceOption.class))).thenReturn(new MockReadChannel(CONTENT)); runner.enqueue("", ImmutableMap.of( BUCKET_ATTR, BUCKET, CoreAttributes.FILENAME.key(), KEY )); runner.run(); ArgumentCaptor<BlobId> blobIdArgumentCaptor = ArgumentCaptor.forClass(BlobId.class); ArgumentCaptor<Storage.BlobSourceOption> blobSourceOptionArgumentCaptor = ArgumentCaptor.forClass(Storage.BlobSourceOption.class); verify(storage).get(blobIdArgumentCaptor.capture()); verify(storage).reader(any(BlobId.class), blobSourceOptionArgumentCaptor.capture()); final BlobId blobId = blobIdArgumentCaptor.getValue(); assertEquals( BUCKET, blobId.getBucket() ); assertEquals( KEY, blobId.getName() ); assertEquals( GENERATION, blobId.getGeneration() ); final Set<Storage.BlobSourceOption> blobSourceOptions = ImmutableSet.copyOf(blobSourceOptionArgumentCaptor.getAllValues()); assertTrue(blobSourceOptions.contains(Storage.BlobSourceOption.generationMatch())); assertEquals( 1, blobSourceOptions.size() ); }
Example 15
Source File: GetMongoIT.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testValidators() { TestRunner runner = TestRunners.newTestRunner(GetMongo.class); Collection<ValidationResult> results; ProcessContext pc; // missing uri, db, collection runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(2, results.size()); Iterator<ValidationResult> it = results.iterator(); Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // missing query - is ok runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME); runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(0, results.size()); // invalid query runner.setProperty(GetMongo.QUERY, "{a: x,y,z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().contains("is invalid because")); // invalid projection runner.setVariable("projection", "{a: x,y,z}"); runner.setProperty(GetMongo.QUERY, "{\"a\": 1}"); runner.setProperty(GetMongo.PROJECTION, "{a: z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().contains("is invalid")); // invalid sort runner.removeProperty(GetMongo.PROJECTION); runner.setProperty(GetMongo.SORT, "{a: x,y,z}"); runner.enqueue(new byte[0]); pc = runner.getProcessContext(); results = new HashSet<>(); if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } Assert.assertEquals(1, results.size()); Assert.assertTrue(results.iterator().next().toString().contains("is invalid")); }
Example 16
Source File: PutMongoRecordIT.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testInsertFlatRecords() throws Exception { TestRunner runner = init(); recordReader.addSchemaField("name", RecordFieldType.STRING); recordReader.addSchemaField("age", RecordFieldType.INT); recordReader.addSchemaField("sport", RecordFieldType.STRING); recordReader.addRecord("John Doe", 48, "Soccer"); recordReader.addRecord("Jane Doe", 47, "Tennis"); recordReader.addRecord("Sally Doe", 47, "Curling"); recordReader.addRecord("Jimmy Doe", 14, null); recordReader.addRecord("Pizza Doe", 14, null); runner.enqueue(""); runner.run(); runner.assertAllFlowFilesTransferred(PutMongoRecord.REL_SUCCESS, 1); // verify 1 doc inserted into the collection assertEquals(5, collection.count()); //assertEquals(doc, collection.find().first()); runner.clearTransferState(); /* * Test it with the client service. */ MongoDBClientService clientService = new MongoDBControllerService(); runner.addControllerService("clientService", clientService); runner.removeProperty(PutMongoRecord.URI); runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI); runner.setProperty(PutMongoRecord.CLIENT_SERVICE, "clientService"); runner.enableControllerService(clientService); runner.assertValid(); collection.deleteMany(new Document()); runner.enqueue(""); runner.run(); runner.assertAllFlowFilesTransferred(PutMongoRecord.REL_SUCCESS, 1); assertEquals(5, collection.count()); }