Search in sources :

Example 61 with Marshaller

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

the class CaseServiceRestOnlyIntegrationTest method testAddDynamicWorkItemTaskNotExistingContainer.

@Test
public void testAddDynamicWorkItemTaskNotExistingContainer() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, ClassLoader.getSystemClassLoader());
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, "not-existing-id");
    valuesMap.put(RestURI.CASE_ID, "not-existing-id");
    Map<String, Object> taskSpecMap = new HashMap<String, Object>();
    taskSpecMap.put(KieServerConstants.CASE_DYNAMIC_NAME_PROP, "Contact car producer");
    taskSpecMap.put(KieServerConstants.CASE_DYNAMIC_NODE_TYPE_PROP, "ContactCarProducer");
    WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), RestURI.CASE_URI + "/" + RestURI.CASE_DYNAMIC_TASK_POST_URI, valuesMap));
    logger.debug("Add dynamic work item: [POST] " + clientRequest.getUri());
    response = clientRequest.request(getMediaType()).post(createEntity(marshaller.marshall(taskSpecMap)));
    Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbString(org.kie.server.api.model.type.JaxbString) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) RestJbpmBaseIntegrationTest(org.kie.server.integrationtests.jbpm.rest.RestJbpmBaseIntegrationTest)

Example 62 with Marshaller

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

the class MarshallerHelper method unmarshal.

public <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) {
    if (data == null || data.isEmpty()) {
        return null;
    }
    MarshallingFormat format = getFormat(marshallingFormat);
    Marshaller marshaller = serverMarshallers.get(format);
    if (marshaller == null) {
        marshaller = MarshallerFactory.getMarshaller(getExtraClasses(registry), format, this.getClass().getClassLoader());
        serverMarshallers.put(format, marshaller);
    }
    Object instance = marshaller.unmarshall(data, unmarshalType, MarshallingFormat.buildParameters(marshallingFormat));
    if (instance instanceof Wrapped) {
        return (T) ((Wrapped) instance).unwrap();
    }
    return (T) instance;
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) Wrapped(org.kie.server.api.model.Wrapped)

Example 63 with Marshaller

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

the class TaskAssigningRuntimeResourceTest method executeFindTasksQuery.

@Test
public void executeFindTasksQuery() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(XSTREAM, this.getClass().getClassLoader());
    Map<String, Object> params = new HashMap<>();
    params.put("param", "value");
    String payload = marshaller.marshall(params);
    List<TaskData> expectedResult = new ArrayList<>();
    expectedResult.add(TaskData.builder().taskId(1L).name("SomeTask").build());
    when(runtimeServiceBase.executeFindTasksQuery(eq(params))).thenReturn(expectedResult);
    String rawResult = resource.executeTasksQuery(httpHeaders, payload).getEntity().toString();
    TaskDataList unMarshalledResult = marshaller.unmarshall(rawResult, TaskDataList.class);
    assertEquals(expectedResult, unMarshalledResult.getItems());
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ArrayList(java.util.ArrayList) TaskDataList(org.kie.server.api.model.taskassigning.TaskDataList) TaskData(org.kie.server.api.model.taskassigning.TaskData) Test(org.junit.Test)

Example 64 with Marshaller

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

the class TaskAssigningRuntimeResourceTest method executePlanning.

@Test
public void executePlanning() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(XSTREAM, this.getClass().getClassLoader());
    PlanningItemList planningItemList = new PlanningItemList();
    String payload = marshaller.marshall(planningItemList);
    PlanningExecutionResult expectedResult = PlanningExecutionResult.builder().build();
    when(runtimeServiceBase.executePlanning(eq(planningItemList), eq(USER_ID))).thenReturn(expectedResult);
    String rawResult = resource.executePlanning(httpHeaders, USER_ID, payload).getEntity().toString();
    String expectedResultInRawFormat = marshaller.marshall(expectedResult);
    assertEquals(expectedResultInRawFormat, rawResult);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) PlanningItemList(org.kie.server.api.model.taskassigning.PlanningItemList) PlanningExecutionResult(org.kie.server.api.model.taskassigning.PlanningExecutionResult) Test(org.junit.Test)

Example 65 with Marshaller

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

the class TaskAssigningRuntimeKieServerExtension method registerQueries.

private void registerQueries() throws IOException {
    try (InputStream stream = this.getClass().getResourceAsStream(TASK_ASSIGNING_QUERY_DEFINITIONS_RESOURCE)) {
        if (stream == null) {
            throw new FileNotFoundException(QUERIES_RESOURCE_NOT_FOUND);
        }
        final Marshaller marshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, getClass().getClassLoader());
        final String queriesString = IOUtils.toString(stream, StandardCharsets.UTF_8);
        final QueryDefinition[] queries = marshaller.unmarshall(queriesString, QueryDefinition[].class);
        if (queries == null || queries.length == 0) {
            LOGGER.info("No queries were found");
            return;
        }
        registerQueries(queries);
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) Marshaller(org.kie.server.api.marshalling.Marshaller) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException)

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