use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicSourceTest method testValidate.
@Test
public void testValidate() {
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
inputProperties.init();
inputProperties.connection.referencedComponent.componentInstanceId.setValue("some value");
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient client = mock(DatabaseClient.class);
when(mockedContainer.getComponentData(inputProperties.connection.getReferencedComponentId(), "connection")).thenReturn(client);
source.initialize(mockedContainer, inputProperties);
ValidationResult result = source.validate(mockedContainer);
assertEquals(ValidationResult.Result.OK, result.getStatus());
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicConnection method connect.
/**
* Creates new {@link DatabaseClient} connection or gets referenced one from container.
*
* @param container
* @return connection to MarkLogic database.
* @throws IOException thrown if referenced connection is not connected.
*/
public DatabaseClient connect(RuntimeContainer container) {
MarkLogicConnectionProperties properties = getMarkLogicConnectionProperties();
if (properties.getReferencedComponentId() != null && container != null) {
DatabaseClient client = (DatabaseClient) container.getComponentData(properties.getReferencedComponentId(), CONNECTION);
if (client != null) {
return client;
}
throw new MarkLogicException(new MarkLogicErrorCode(MESSAGES.getMessage("error.invalid.referenceConnection", properties.getReferencedComponentId())));
}
SecurityContext context = "BASIC".equals(properties.authentication.getValue()) ? new DatabaseClientFactory.BasicAuthContext(properties.username.getValue(), properties.password.getValue()) : new DatabaseClientFactory.DigestAuthContext(properties.username.getValue(), properties.password.getValue());
DatabaseClient client = DatabaseClientFactory.newClient(properties.host.getValue(), properties.port.getValue(), properties.database.getValue(), context);
testConnection(client);
LOGGER.info("Connected to MarkLogic server");
if (container != null) {
container.setComponentData(container.getCurrentComponentId(), CONNECTION, client);
LOGGER.info("Connection stored in container");
}
return client;
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicDataSourceTest method testValidate.
@Test
public void testValidate() {
datasource.getMarkLogicConnectionProperties().referencedComponent.componentInstanceId.setValue("reference");
DatabaseClient client = Mockito.mock(DatabaseClient.class);
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
Mockito.when(container.getComponentData("reference", MarkLogicConnection.CONNECTION)).thenReturn(client);
Assert.assertEquals(Result.OK, datasource.validate(container).getStatus());
Mockito.verify(container, Mockito.only()).getComponentData("reference", MarkLogicConnection.CONNECTION);
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicRowProcessorTest method testCloseReferencedConnectionNotReleased.
@Test
public void testCloseReferencedConnectionNotReleased() throws IOException {
DatabaseClient mockedClient = mock(DatabaseClient.class);
MarkLogicInputSink mockedSink = mock(MarkLogicInputSink.class);
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
inputProperties.init();
inputProperties.connection.referencedComponent.componentInstanceId.setValue(MarkLogicConnectionDefinition.COMPONENT_NAME + "_1");
MarkLogicInputWriteOperation writeOperation = new MarkLogicInputWriteOperation(mockedSink, inputProperties);
MarkLogicRowProcessor rowProcessor = writeOperation.createWriter(null);
when(mockedSink.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
rowProcessor.open("1");
verify(mockedClient).newDocumentManager();
rowProcessor.close();
verifyNoMoreInteractions(mockedClient);
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicRowProcessorTest method testClose.
@Test
public void testClose() throws IOException {
DatabaseClient mockedClient = mock(DatabaseClient.class);
MarkLogicInputSink mockedSink = mock(MarkLogicInputSink.class);
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
inputProperties.init();
MarkLogicInputWriteOperation writeOperation = new MarkLogicInputWriteOperation(mockedSink, inputProperties);
MarkLogicRowProcessor rowProcessor = writeOperation.createWriter(null);
when(mockedSink.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
String uId = "123";
rowProcessor.open(uId);
Result result = rowProcessor.close();
assertNotNull(result);
assertEquals(uId, result.getuId());
verify(mockedClient).release();
}
Aggregations