Search in sources :

Example 11 with Marshaller

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

the class KieServerBackwardCompatDroolsIntegrationTest method testCallContainerWithStringPayloadRuleClient.

@Test
public void testCallContainerWithStringPayloadRuleClient() 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<String> reply = ruleClient.executeCommands(CONTAINER_ID, marshalledCommands);
    Assert.assertEquals(ServiceResponse.ResponseType.SUCCESS, reply.getType());
    ExecutionResults results = marshaller.unmarshall(reply.getResult(), ExecutionResultImpl.class);
    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) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BeforeClass(org.junit.BeforeClass) Test(org.junit.Test)

Example 12 with Marshaller

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

the class RestMalformedRequestIntegrationTest method testInvalidCommandBodyOnCallContainer.

@Test
public void testInvalidCommandBodyOnCallContainer() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, this.getClass().getClassLoader());
    Response response = null;
    try {
        // empty commands can be considered as invalid request
        String body = marshaller.marshall(new BatchExecutionCommandImpl());
        WebTarget clientRequest = newRequest(TestConfig.getKieServerHttpUrl() + "/containers/instances/" + CONTAINER_ID);
        response = clientRequest.request(getMediaType()).post(createEntity(body));
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
        ServiceResponse<KieContainerResource> serviceResponse = response.readEntity(new GenericType<ServiceResponse<KieContainerResource>>() {
        });
        assertEquals(ServiceResponse.ResponseType.FAILURE, serviceResponse.getType());
        assertEquals("Bad request, no commands to be executed - either wrong format or no data", serviceResponse.getMsg());
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception on empty body", e);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ServiceResponse(org.kie.server.api.model.ServiceResponse) Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) ServiceResponse(org.kie.server.api.model.ServiceResponse) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) WebTarget(javax.ws.rs.client.WebTarget) KieContainerResource(org.kie.server.api.model.KieContainerResource) RestOnlyBaseIntegrationTest(org.kie.server.integrationtests.shared.basetests.RestOnlyBaseIntegrationTest) Test(org.junit.Test)

Example 13 with Marshaller

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

the class MarshallingRoundTripNestedClassesWithAnnotationsTest method testJSON.

@Test
public void testJSON() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestObject());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 14 with Marshaller

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

the class MarshallingRoundTripNestedClassesWithAnnotationsTest method testJaxb.

@Test
public void testJaxb() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(getCustomClasses(), MarshallingFormat.JAXB, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestObject());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 15 with Marshaller

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

the class MarshallingRoundTripTest method testMapWithDateJSON.

@Test
public void testMapWithDateJSON() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, getClass().getClassLoader());
    Map<String, Object> map = new HashMap<>();
    map.put("date", new Date());
    verifyMarshallingRoundTrip(marshaller, map);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) Date(java.util.Date) 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