Search in sources :

Example 1 with UpdateCommand

use of org.drools.core.command.runtime.rule.UpdateCommand in project drools by kiegroup.

the class CommandSerializationTest method updateCommandTest.

// TESTS ----------------------------------------------------------------------------------------------------------------------
@Test
public void updateCommandTest() throws Exception {
    DisconnectedFactHandle discFactHandle = new DisconnectedFactHandle(2, 3, 4, 5l, "entry-point-id", "str-obj", true);
    DisconnectedFactHandle copyDiscFactHandle = roundTrip(discFactHandle);
    verifyDisconnectedFactHandle(discFactHandle, copyDiscFactHandle);
    UpdateCommand cmd = new UpdateCommand(discFactHandle, "new-str-object");
    UpdateCommand copyCmd = roundTrip(cmd);
    verifyDisconnectedFactHandle(discFactHandle, copyCmd.getHandle());
    assertEquals("entry point", cmd.getEntryPoint(), copyCmd.getEntryPoint());
    assertEquals("object", cmd.getObject(), copyCmd.getObject());
}
Also used : DisconnectedFactHandle(org.drools.core.common.DisconnectedFactHandle) UpdateCommand(org.drools.core.command.runtime.rule.UpdateCommand) Test(org.junit.Test)

Example 2 with UpdateCommand

use of org.drools.core.command.runtime.rule.UpdateCommand in project drools by kiegroup.

the class XStreamXMLTest method testUpdateCommand.

@Test
public void testUpdateCommand() {
    FactHandle factHandle = DefaultFactHandle.createFromExternalFormat("0:1:10:10:20:null:NON_TRAIT:null");
    UpdateCommand cmd = new UpdateCommand(factHandle, new Message("Hello World!"), new String[] { "msg" });
    String xmlString = xstream.toXML(cmd);
    String expected = "<update fact-handle=\"0:1:10:10:20:null:NON_TRAIT:null\" entryPoint=\"DEFAULT\">\n" + "  <org.drools.xml.support.XStreamXMLTest_-Message>\n" + "    <msg>Hello World!</msg>\n" + "  </org.drools.xml.support.XStreamXMLTest_-Message>\n" + "  <modifiedProperty value=\"msg\"/>\n" + "</update>";
    Assertions.assertThat(expected).isEqualToIgnoringWhitespace(xmlString);
    UpdateCommand cmd2 = (UpdateCommand) xstream.fromXML(xmlString);
    Assert.assertEquals(factHandle.toExternalForm(), cmd2.getHandle().toExternalForm());
    Assert.assertEquals(1, cmd2.getModifiedProperties().length);
    Assert.assertEquals("msg", cmd2.getModifiedProperties()[0]);
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) UpdateCommand(org.drools.core.command.runtime.rule.UpdateCommand) Test(org.junit.Test)

Aggregations

UpdateCommand (org.drools.core.command.runtime.rule.UpdateCommand)2 Test (org.junit.Test)2 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)1 DisconnectedFactHandle (org.drools.core.common.DisconnectedFactHandle)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1