Search in sources :

Example 6 with Marshaller

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

the class JSONUnmarshallingTest method unmarshalNonExistingClassInDroolsCommand.

private Object unmarshalNonExistingClassInDroolsCommand() {
    Set<Class<?>> extraClasses = new HashSet<Class<?>>();
    Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
    String json = "{\n" + "  \"lookup\" : \"StatelessKieSession\",\n" + "    \"commands\" : [ {\n" + "      \"insert\" : {\n" + "        \"object\" : {\"com.nonexisting.Person\":{\"name\":\"taro\",\"age\":\"20\"}},\n" + "        \"out-identifier\" : \"person\",\n" + "        \"return-object\" : \"true\",\n" + "        \"entry-point\" : \"DEFAULT\"\n" + "       }\n" + "    }, {\n" + "        \"fire-all-rules\" : { }\n" + "   } ]\n" + "}";
    return marshaller.unmarshall(json, BatchExecutionCommandImpl.class);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashSet(java.util.HashSet)

Example 7 with Marshaller

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

the class JSONUnmarshallingTest method unmarshalNonExistingClass.

private Object unmarshalNonExistingClass() {
    Set<Class<?>> extraClasses = new HashSet<Class<?>>();
    Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
    String json = "{\"com.nonexisting.Person\":{\"name\":\"taro\",\"age\":\"20\"}}";
    return marshaller.unmarshall(json, Object.class);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashSet(java.util.HashSet)

Example 8 with Marshaller

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

the class StringContentJSONTest method testStringContentMap.

@Test
public void testStringContentMap() {
    Set<Class<?>> extraClasses = new HashSet<Class<?>>();
    Marshaller marshaller = MarshallerFactory.getMarshaller(extraClasses, MarshallingFormat.JSON, this.getClass().getClassLoader());
    String jsonMap = "{\"name\" : \"value\"}";
    StringContentMap map = new StringContentMap(jsonMap);
    // content must be of exact value as given in constructor
    String marshall = marshaller.marshall(map);
    assertEquals(jsonMap, marshall);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Marshaller

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

the class DroolsJmsResponseHandlerIntegrationTest method testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler.

@Test
public void testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    ruleClient.setResponseHandler(asyncResponseHandler);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME));
    commands.add(commandsFactory.newStartProcess(PROCESS_ID));
    commands.add(commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
    ServiceResponse<?> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    assertThat(response).isNull();
    ExecutionResults result = responseCallback.get(ExecutionResultImpl.class);
    List<String> outcome = (List<String>) result.getValue(LIST_OUTPUT_NAME);
    assertThat(outcome).isNotNull();
    assertThat(outcome).containsExactly("Rule from first ruleflow group executed", "Rule from second ruleflow group executed");
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) DroolsKieServerBaseIntegrationTest(org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)

Example 10 with Marshaller

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

the class KieServerDroolsIntegrationTest method testCallContainerWithStringPayload.

@Test
public void testCallContainerWithStringPayload() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), kjarClassLoader);
    Object message = createInstance(MESSAGE_CLASS_NAME);
    KieServerReflections.setValue(message, MESSAGE_TEXT_FIELD, MESSAGE_REQUEST);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
    commands.add(commandsFactory.newInsert(message, MESSAGE_OUT_IDENTIFIER));
    commands.add(commandsFactory.newFireAllRules());
    String marshalledCommands = marshaller.marshall(batchExecution);
    ServiceResponse<ExecutionResults> reply = ruleClient.executeCommandsWithResults(CONTAINER_ID, marshalledCommands);
    Assert.assertEquals(ServiceResponse.ResponseType.SUCCESS, reply.getType());
    ExecutionResults results = reply.getResult();
    Object value = results.getValue(MESSAGE_OUT_IDENTIFIER);
    Assert.assertEquals(MESSAGE_RESPONSE, KieServerReflections.valueOf(value, MESSAGE_TEXT_FIELD));
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) CreateContainerCommand(org.kie.server.api.commands.CreateContainerCommand) CallContainerCommand(org.kie.server.api.commands.CallContainerCommand) Command(org.kie.api.command.Command) KieServerCommand(org.kie.server.api.model.KieServerCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) DisposeContainerCommand(org.kie.server.api.commands.DisposeContainerCommand) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BeforeClass(org.junit.BeforeClass) Test(org.junit.Test)

Aggregations

Marshaller (org.kie.server.api.marshalling.Marshaller)65 Test (org.junit.Test)48 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)11 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)9 Response (javax.ws.rs.core.Response)8 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)8 Command (org.kie.api.command.Command)8 ExecutionResults (org.kie.api.runtime.ExecutionResults)8 HashSet (java.util.HashSet)7 JaxbLong (org.kie.server.api.model.type.JaxbLong)6 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 CallContainerCommand (org.kie.server.api.commands.CallContainerCommand)3 KieContainerResource (org.kie.server.api.model.KieContainerResource)3 KieServerCommand (org.kie.server.api.model.KieServerCommand)3 ServiceResponse (org.kie.server.api.model.ServiceResponse)3 Date (java.util.Date)2 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)2