Search in sources :

Example 1 with JSONMarshaller

use of org.kie.server.api.marshalling.json.JSONMarshaller in project droolsjbpm-integration by kiegroup.

the class JSONMarshallerTest method testCapitalizedWrapObjectFieldnames.

@Test
public void testCapitalizedWrapObjectFieldnames() throws Exception {
    Marshaller marshaller = new JSONMarshaller(new HashSet<>(), getClass().getClassLoader(), false, true);
    BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl();
    batch.addCommand(new InsertObjectCommand(new Order("all")));
    String converted = marshaller.marshall(batch);
    String expectedMarshalled = "{ \"lookup\" : null, \"commands\" : [ { \"insert\" : " + "{ \"object\" : {\"org.kie.server.api.marshalling.JSONMarshallerTest$Order\":{ \"ORDER_ID\" : \"all\" }}, " + "\"out-identifier\" : null, \"return-object\" : true, \"entry-point\" : \"DEFAULT\", \"disconnected\" : false } } ] }";
    JSONAssert.assertEquals(expectedMarshalled, converted, STRICT);
    BatchExecutionCommandImpl unconverted = marshaller.unmarshall(converted, BatchExecutionCommandImpl.class);
    assertEquals("all", ((Order) ((InsertObjectCommand) unconverted.getCommands().get(0)).getObject()).getORDER_ID());
}
Also used : JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) InsertObjectCommand(org.drools.core.command.runtime.rule.InsertObjectCommand) Test(org.junit.Test)

Example 2 with JSONMarshaller

use of org.kie.server.api.marshalling.json.JSONMarshaller in project droolsjbpm-integration by kiegroup.

the class JSONMarshallerTest method testCapitalizedFieldnames.

@Test
public void testCapitalizedFieldnames() throws Exception {
    Marshaller marshaller = new JSONMarshaller(new HashSet<>(), getClass().getClassLoader(), false, true);
    Order order = new Order("all");
    String converted = marshaller.marshall(order);
    String expectedMarshalled = "{\"ORDER_ID\" : \"all\"}";
    JSONAssert.assertEquals(expectedMarshalled, converted, STRICT);
    Order unconverted = marshaller.unmarshall(converted, Order.class);
    assertEquals("all", unconverted.getORDER_ID());
}
Also used : JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) Test(org.junit.Test)

Example 3 with JSONMarshaller

use of org.kie.server.api.marshalling.json.JSONMarshaller in project droolsjbpm-integration by kiegroup.

the class Person method testCapitalizedWrapObjectFieldnames.

@Test
public void testCapitalizedWrapObjectFieldnames() throws Exception {
    Marshaller marshaller = new JSONMarshaller(new HashSet<>(), getClass().getClassLoader(), false, true);
    BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl();
    batch.addCommand(new InsertObjectCommand(new Order("all")));
    String converted = marshaller.marshall(batch);
    String expectedMarshalled = "{ \"lookup\" : null, \"commands\" : [ { \"insert\" : " + "{ \"object\" : {\"org.kie.server.api.marshalling.JSONMarshallerTest$Order\":{ \"ORDER_ID\" : \"all\" }}, " + "\"out-identifier\" : null, \"return-object\" : true, \"entry-point\" : \"DEFAULT\", \"disconnected\" : false } } ] }";
    JSONAssert.assertEquals(expectedMarshalled, converted, STRICT);
    BatchExecutionCommandImpl unconverted = marshaller.unmarshall(converted, BatchExecutionCommandImpl.class);
    assertEquals("all", ((Order) ((InsertObjectCommand) unconverted.getCommands().get(0)).getObject()).getORDER_ID());
}
Also used : JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) InsertObjectCommand(org.drools.core.command.runtime.rule.InsertObjectCommand) Test(org.junit.Test)

Example 4 with JSONMarshaller

use of org.kie.server.api.marshalling.json.JSONMarshaller in project droolsjbpm-integration by kiegroup.

the class Person method testCapitalizedFieldnames.

@Test
public void testCapitalizedFieldnames() throws Exception {
    Marshaller marshaller = new JSONMarshaller(new HashSet<>(), getClass().getClassLoader(), false, true);
    Order order = new Order("all");
    String converted = marshaller.marshall(order);
    String expectedMarshalled = "{\"ORDER_ID\" : \"all\"}";
    JSONAssert.assertEquals(expectedMarshalled, converted, STRICT);
    Order unconverted = marshaller.unmarshall(converted, Order.class);
    assertEquals("all", unconverted.getORDER_ID());
}
Also used : JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) Test(org.junit.Test)

Example 5 with JSONMarshaller

use of org.kie.server.api.marshalling.json.JSONMarshaller in project droolsjbpm-integration by kiegroup.

the class Person method testLegacyFieldnames.

@Test
public void testLegacyFieldnames() throws Exception {
    Marshaller marshaller = new JSONMarshaller(new HashSet<>(), getClass().getClassLoader(), false, false);
    Order order = new Order("all");
    String converted = marshaller.marshall(order);
    String expectedMarshalled = "{\"order_ID\" : \"all\"}";
    JSONAssert.assertEquals(expectedMarshalled, converted, STRICT);
    Order unconverted = marshaller.unmarshall(converted, Order.class);
    assertEquals("all", unconverted.getORDER_ID());
}
Also used : JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) JSONMarshaller(org.kie.server.api.marshalling.json.JSONMarshaller) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 JSONMarshaller (org.kie.server.api.marshalling.json.JSONMarshaller)9 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)4 InsertObjectCommand (org.drools.core.command.runtime.rule.InsertObjectCommand)4 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1