use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.
the class AbstractTestGetInfluxDatabase_2 method before.
@Before
public void before() throws IOException, GeneralSecurityException, InitializationException {
InfluxDBClient mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
mockQueryApi = Mockito.mock(QueryApi.class);
Mockito.doAnswer(invocation -> mockQueryApi).when(mockInfluxDBClient).getQueryApi();
Mockito.doAnswer(invocation -> {
if (queryOnErrorValue != null) {
// noinspection unchecked
Consumer<Exception> onError = invocation.getArgument(3, Consumer.class);
onError.accept(queryOnErrorValue);
}
queryOnResponseRecords.forEach(record -> {
// noinspection unchecked
BiConsumer<Cancellable, String> onRecord = invocation.getArgument(2, BiConsumer.class);
onRecord.accept(Mockito.mock(Cancellable.class), record);
});
boolean wasException = queryOnErrorValue != null;
try {
return queryAnswer.answer(invocation);
} catch (Exception e) {
wasException = true;
throw e;
} finally {
if (!wasException) {
Runnable onComplete = invocation.getArgument(4, Runnable.class);
onComplete.run();
}
}
}).when(mockQueryApi).queryRaw(Mockito.any(Query.class), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any());
processor = Mockito.spy(new GetInfluxDatabase_2());
runner = TestRunners.newTestRunner(processor);
runner.setProperty(GetInfluxDatabase_2.ORG, "my-org");
runner.setProperty(GetInfluxDatabase_2.QUERY, "from(bucket:\"my-bucket\") |> range(start: 0) |> last()");
runner.setProperty(GetInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
MockProcessContext context = new MockProcessContext(processor);
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
logger = initContext.getLogger();
processor.initialize(initContext);
processor.onScheduled(runner.getProcessContext());
processor.initWriterFactory(runner.getProcessContext());
}
use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.
the class AbstractTestPutInfluxDatabaseRecord_2 method before.
@Before
public void before() throws InitializationException, IOException, GeneralSecurityException {
MockitoAnnotations.initMocks(this);
mockWriteApi = Mockito.mock(WriteApiBlocking.class);
mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
Mockito.doAnswer(invocation -> mockWriteApi).when(mockInfluxDBClient).getWriteApiBlocking();
processor = Mockito.spy(new PutInfluxDatabaseRecord_2());
runner = TestRunners.newTestRunner(processor);
runner.setProperty(PutInfluxDatabaseRecord_2.ORG, "my-org");
runner.setProperty(PutInfluxDatabaseRecord_2.BUCKET, "my-bucket");
runner.setProperty(InfluxDBUtils.MEASUREMENT, "nifi-measurement");
runner.setProperty(InfluxDBUtils.FIELDS, "nifi-field");
runner.setProperty(AbstractInfluxDatabaseProcessor.RECORD_READER_FACTORY, "recordReader");
runner.setProperty(PutInfluxDatabaseRecord_2.INFLUX_DB_SERVICE, "influxdb-service");
recordReader = new MockRecordParser();
runner.addControllerService("recordReader", recordReader);
runner.enableControllerService(recordReader);
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
Mockito.doAnswer(invocation -> {
Mockito.doAnswer(writeAnswer).when(mockWriteApi).writePoints(Mockito.any(), Mockito.any(), pointCapture.capture());
return mockInfluxDBClient;
}).when(influxDatabaseService).create();
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
MockProcessContext context = new MockProcessContext(processor);
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
logger = initContext.getLogger();
processor.initialize(initContext);
/**
* Manually call onScheduled because it si not called by
* org.apache.nifi.util.StandardProcessorTestRunner#run(int, boolean, boolean, long).
* Bug in Mockito-CGLIB (https://github.com/mockito/mockito/issues/204)... remove after upgrade Mockito to 2.x
*/
processor.onScheduled(runner.getProcessContext());
}
use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.
the class ITGetInfluxDatabaseRecord_2 method setUp.
@Before
public void setUp() throws Exception {
init();
GetInfluxDatabaseRecord_2 putInfluxDatabase_2 = new GetInfluxDatabaseRecord_2();
runner = TestRunners.newTestRunner(putInfluxDatabase_2);
runner.setValidateExpressionUsage(false);
runner.setProperty(GetInfluxDatabaseRecord_2.INFLUX_DB_SERVICE, "influxdb-service");
runner.setProperty(GetInfluxDatabaseRecord_2.ORG, organization.getId());
runner.setProperty(GetInfluxDatabaseRecord_2.QUERY, "from(bucket:\"" + bucketName + "\") |> range(start: 0)");
runner.setProperty(GetInfluxDatabaseRecord_2.LOG_LEVEL, "BODY");
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_URL, INFLUX_DB_2);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
recordWriter = new AvroRecordSetWriter();
runner.addControllerService("writer", recordWriter);
runner.setProperty(recordWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.INHERIT_RECORD_SCHEMA);
runner.setProperty(GetInfluxDatabaseRecord_2.WRITER_FACTORY, "writer");
runner.enableControllerService(recordWriter);
runner.assertValid();
}
use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.
the class ITGetInfluxDatabase_2 method setUp.
@Before
public void setUp() throws Exception {
init();
GetInfluxDatabase_2 putInfluxDatabase_2 = new GetInfluxDatabase_2();
runner = TestRunners.newTestRunner(putInfluxDatabase_2);
runner.setValidateExpressionUsage(false);
runner.setProperty(GetInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
runner.setProperty(GetInfluxDatabase_2.ORG, organization.getId());
runner.setProperty(GetInfluxDatabase_2.QUERY, "from(bucket:\"" + bucketName + "\") |> range(start: 0)");
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_URL, INFLUX_DB_2);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
}
use of org.influxdata.nifi.services.InfluxDatabaseService_2 in project nifi-influxdb-bundle by influxdata.
the class TestPutInfluxDatabase_2 method setUp.
@Before
public void setUp() throws InitializationException, IOException, GeneralSecurityException {
mockWriteApi = Mockito.mock(WriteApiBlocking.class);
mockInfluxDBClient = Mockito.mock(InfluxDBClient.class);
Mockito.doAnswer(invocation -> mockWriteApi).when(mockInfluxDBClient).getWriteApiBlocking();
PutInfluxDatabase_2 putInfluxDatabase_2 = new PutInfluxDatabase_2();
runner = TestRunners.newTestRunner(putInfluxDatabase_2);
runner.setProperty(PutInfluxDatabase_2.INFLUX_DB_SERVICE, "influxdb-service");
runner.setProperty(PutInfluxDatabase_2.BUCKET, "my-bucket");
runner.setProperty(PutInfluxDatabase_2.ORG, "my-org");
InfluxDatabaseService_2 influxDatabaseService = Mockito.spy(new StandardInfluxDatabaseService_2());
Mockito.doAnswer(invocation -> mockInfluxDBClient).when(influxDatabaseService).create();
runner.addControllerService("influxdb-service", influxDatabaseService);
runner.setProperty(influxDatabaseService, INFLUX_DB_ACCESS_TOKEN, "my-token");
runner.enableControllerService(influxDatabaseService);
}
Aggregations