Search in sources :

Example 11 with Audits

use of io.atlasmap.v2.Audits in project atlasmap by atlasmap.

the class AtlasEndpointTest method perform.

private void perform(List<DataSource> dataSources, String sourceDocId, String targetDocId, boolean fromStream) throws Exception {
    final AtlasMapping mapping = new AtlasMapping();
    mapping.getDataSource().addAll(dataSources);
    final AtlasContext context = spy(AtlasContext.class);
    final AtlasSession session = spy(AtlasSession.class);
    when(context.createSession()).thenReturn(session);
    when(session.getMapping()).thenReturn(mapping);
    when(session.getAudits()).thenReturn(new Audits());
    final AtlasEndpoint endpoint = new AtlasEndpoint("atlas:test.xml", new AtlasComponent(), "test.xml");
    endpoint.setAtlasContext(context);
    final Exchange exchange = spy(Exchange.class);
    final Message inMessage = spy(Message.class);
    when(inMessage.getBody()).thenReturn(fromStream ? new ByteArrayInputStream("{test}".getBytes()) : "{test}");
    when(inMessage.getBody(String.class)).thenReturn("{test}");
    when(exchange.getIn()).thenReturn(inMessage);
    if (sourceDocId == null) {
        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) {
                LOG.debug("setDefaultSourceDocument({})", invocation.getArgument(0).toString());
                assertEquals("{test}", invocation.getArgument(0).toString());
                return null;
            }
        }).when(session).setDefaultSourceDocument(any());
    } else {
        doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) {
                LOG.debug("setSourceDocument({}, {})", invocation.getArgument(0), invocation.getArgument(1));
                assertEquals(sourceDocId, invocation.getArgument(0));
                assertEquals("{test}", invocation.getArgument(1));
                return null;
            }
        }).when(session).setSourceDocument(any(), any());
    }
    final Message outMessage = spy(Message.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            LOG.debug("setBody({})", invocation.getArgument(0).toString());
            assertEquals("<target/>", invocation.getArgument(0));
            return null;
        }
    }).when(outMessage).setBody(any());
    doNothing().when(outMessage).setHeaders(any());
    doNothing().when(outMessage).setAttachments(any());
    if (targetDocId == null) {
        when(session.getDefaultTargetDocument()).thenAnswer(new Answer<Object>() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                LOG.debug("getDefaultTargetDocument()");
                return "<target/>";
            }
        });
    } else {
        when(session.getTargetDocument(any())).thenAnswer(new Answer<Object>() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                LOG.debug("getTargetDocument({})", invocation.getArgument(0).toString());
                assertEquals(targetDocId, invocation.getArgument(0));
                return "<target/>";
            }
        });
    }
    when(exchange.getOut()).thenReturn(outMessage);
    endpoint.onExchange(exchange);
}
Also used : Message(org.apache.camel.Message) Exchange(org.apache.camel.Exchange) AtlasMapping(io.atlasmap.v2.AtlasMapping) Audits(io.atlasmap.v2.Audits) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession)

Example 12 with Audits

use of io.atlasmap.v2.Audits in project atlasmap by atlasmap.

the class JsonFieldWriterTest method read.

private AtlasInternalSession read(Path path, FieldType outputFieldType, String fieldPath) throws IOException, AtlasException {
    String document = new String(Files.readAllBytes(path));
    reader.setDocument(document);
    JsonField jsonField = AtlasJsonModelFactory.createJsonField();
    jsonField.setPath(fieldPath);
    jsonField.setFieldType(outputFieldType);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(jsonField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Aggregations

Audits (io.atlasmap.v2.Audits)9 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)5 Head (io.atlasmap.spi.AtlasInternalSession.Head)5 Audit (io.atlasmap.v2.Audit)4 Validations (io.atlasmap.v2.Validations)3 AtlasSession (io.atlasmap.api.AtlasSession)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)2 XmlField (io.atlasmap.xml.v2.XmlField)2 Test (org.junit.Test)2 AtlasContext (io.atlasmap.api.AtlasContext)1 JsonField (io.atlasmap.json.v2.JsonField)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 Collection (io.atlasmap.v2.Collection)1 ConstantField (io.atlasmap.v2.ConstantField)1 Field (io.atlasmap.v2.Field)1 LookupTable (io.atlasmap.v2.LookupTable)1 Mapping (io.atlasmap.v2.Mapping)1 Mappings (io.atlasmap.v2.Mappings)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1