Search in sources :

Example 1 with JSONReplicationMessageParserImpl

use of com.dexels.replication.impl.json.JSONReplicationMessageParserImpl in project navajo by Dexels.

the class TestProtobufConversion method testConversion.

@Test
public void testConversion() throws JsonGenerationException, JsonMappingException, IOException {
    ReplicationMessage createReplicationMessage = createReplicationMessage();
    // convert to protobuf
    byte[] serializedMessage = ReplicationFactory.getInstance().serialize(createReplicationMessage);
    System.out.println(new String(serializedMessage));
    assertNotNull(serializedMessage);
    // parse protobuf
    ReplicationMessage rmsg = ReplicationFactory.getInstance().parseBytes(Optional.empty(), serializedMessage);
    System.err.println("Rescribe: " + new String(rmsg.toBytes(new JSONReplicationMessageParserImpl())));
    Navajo rr = JsonTmlFactory.getInstance().toReplicationNavajo(rmsg, "Tenant", "Table", Optional.of("Datasource"));
    rr.write(System.out);
    // Check
    Assert.assertEquals(6, rr.getMessage("Transaction/Columns").getArraySize());
}
Also used : JSONReplicationMessageParserImpl(com.dexels.replication.impl.json.JSONReplicationMessageParserImpl) Navajo(com.dexels.navajo.document.Navajo) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) Test(org.junit.Test)

Example 2 with JSONReplicationMessageParserImpl

use of com.dexels.replication.impl.json.JSONReplicationMessageParserImpl in project navajo by Dexels.

the class TestJsonConversion method testConversion.

@Test
public void testConversion() throws IOException {
    InputStream resource = TestJsonConversion.class.getResourceAsStream("testtml.xml");
    Navajo base = NavajoFactory.getInstance().createNavajo(resource);
    Message m = base.getMessage("Pool");
    ObjectNode on = JsonTmlFactory.getInstance().toNode(m, "ble");
    JSONReplicationMessageParserImpl parser = new JSONReplicationMessageParserImpl();
    ReplicationMessage rmsg = parser.parseJson(Optional.empty(), on);
    ObjectMapper mapper = new ObjectMapper();
    logger.info("Before:\n");
    StringWriter sw = new StringWriter();
    mapper.writerWithDefaultPrettyPrinter().writeValue(sw, on);
    logger.info("Value: {}", sw);
    Optional<List<ImmutableMessage>> r = rmsg.subMessages("Standings");
    Assert.assertTrue(r.isPresent());
    Assert.assertEquals(12, r.get().size());
    Navajo rr = JsonTmlFactory.getInstance().toReplicationNavajo(rmsg, "Tenant", "Table", Optional.of("Datasource"));
    Assert.assertEquals(10, rr.getMessage("Transaction/Columns").getArraySize());
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) JSONReplicationMessageParserImpl(com.dexels.replication.impl.json.JSONReplicationMessageParserImpl) List(java.util.List) Navajo(com.dexels.navajo.document.Navajo) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with JSONReplicationMessageParserImpl

use of com.dexels.replication.impl.json.JSONReplicationMessageParserImpl in project navajo by Dexels.

the class TestSerializeReplicationMessage method testRepl.

@Test
public void testRepl() {
    ReplicationMessageParser parser = new JSONReplicationMessageParserImpl();
    ImmutableMessage m = parser.parseStream(this.getClass().getClassLoader().getResourceAsStream("person.json")).message();
    StreamDocument.replicationMessageToStreamEvents("Person", m, false).compose(StreamDocument.inNavajo("TestService", Optional.empty(), Optional.empty())).lift(StreamDocument.serialize()).lift(StreamDocument.decode("UTF-8")).blockingForEach(e -> {
        System.err.print(e);
    });
}
Also used : ReplicationMessageParser(com.dexels.replication.api.ReplicationMessageParser) JSONReplicationMessageParserImpl(com.dexels.replication.impl.json.JSONReplicationMessageParserImpl) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Test(org.junit.Test)

Aggregations

JSONReplicationMessageParserImpl (com.dexels.replication.impl.json.JSONReplicationMessageParserImpl)3 Test (org.junit.Test)3 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)2 Navajo (com.dexels.navajo.document.Navajo)2 ReplicationMessage (com.dexels.replication.api.ReplicationMessage)2 Message (com.dexels.navajo.document.Message)1 ReplicationMessageParser (com.dexels.replication.api.ReplicationMessageParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1