use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicSourceOrSinkTest method testValidateCannotConnect.
@Test
public void testValidateCannotConnect() {
DatabaseClient mockedClient = mock(DatabaseClient.class);
when(mockedClient.openTransaction()).thenThrow(new ForbiddenUserException("User not allowed"));
PowerMockito.mockStatic(DatabaseClientFactory.class);
when(DatabaseClientFactory.newClient(anyString(), anyInt(), anyString(), (DatabaseClientFactory.SecurityContext) anyObject())).thenReturn(mockedClient);
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProperties");
sourceOrSink.initialize(null, inputProperties);
assertEquals(Result.ERROR, sourceOrSink.validate(null).getStatus());
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicWriterTest method testInitDocManagerBinary.
@Test
public void testInitDocManagerBinary() throws IOException {
MarkLogicSink sink = new MarkLogicSink();
MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
properties.init();
properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
properties.docType.setValue(MarkLogicOutputProperties.DocType.BINARY);
sink.ioProperties = properties;
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient mockedClient = mock(DatabaseClient.class);
Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
writer = sink.createWriteOperation().createWriter(mockedContainer);
writer.open("123");
verify(mockedClient).newBinaryDocumentManager();
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicWriterTest method testInitDocManagerText.
@Test
public void testInitDocManagerText() throws IOException {
MarkLogicSink sink = new MarkLogicSink();
MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
properties.init();
properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
properties.docType.setValue(MarkLogicOutputProperties.DocType.PLAIN_TEXT);
sink.ioProperties = properties;
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient mockedClient = mock(DatabaseClient.class);
Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
writer = sink.createWriteOperation().createWriter(mockedContainer);
writer.open("123");
verify(mockedClient).newTextDocumentManager();
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicWriterTest method testInitDocManagerJSON.
@Test
public void testInitDocManagerJSON() throws IOException {
MarkLogicSink sink = new MarkLogicSink();
MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
properties.init();
properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
properties.docType.setValue(MarkLogicOutputProperties.DocType.JSON);
sink.ioProperties = properties;
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient mockedClient = mock(DatabaseClient.class);
Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
writer = sink.createWriteOperation().createWriter(mockedContainer);
writer.open("123");
verify(mockedClient).newJSONDocumentManager();
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicCriteriaReaderTest method testStartWithoutDocContentField.
@Test
public void testStartWithoutDocContentField() throws IOException {
StringQueryDefinition mockedStringQueryDefinition = mock(StringQueryDefinition.class);
QueryManager mockedQueryManager = mock(QueryManager.class);
when(mockedQueryManager.newStringDefinition()).thenReturn(mockedStringQueryDefinition);
when(mockedQueryManager.newStringDefinition(anyString())).thenReturn(mockedStringQueryDefinition);
DatabaseClient mockedClient = mock(DatabaseClient.class);
when(mockedClient.newDocumentManager()).thenReturn(null);
when(mockedClient.newQueryManager()).thenReturn(mockedQueryManager);
SearchHandle searchHandle = Mockito.mock(SearchHandle.class);
Mockito.when(mockedQueryManager.search(Mockito.eq(mockedStringQueryDefinition), Mockito.any(SearchHandle.class))).thenReturn(searchHandle);
MarkLogicSource mockedSource = mock(MarkLogicSource.class);
when(mockedSource.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
MarkLogicInputProperties properties = new MarkLogicInputProperties("inputProperties");
properties.init();
Schema.Field docIdField = new Schema.Field("docId", AvroUtils._string(), null, (Object) null, Schema.Field.Order.IGNORE);
properties.datasetProperties.main.schema.setValue(Schema.createRecord("docIdOnlySchema", null, null, false, Collections.singletonList(docIdField)));
MarkLogicCriteriaReader criteriaReader = new MarkLogicCriteriaReader(mockedSource, null, properties);
System.out.println(criteriaReader.start());
}
Aggregations