Search in sources :

Example 36 with Marshaller

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

the class JbpmRestIntegrationTest method testUploadListDownloadDocument.

@Test
public void testUploadListDownloadDocument() throws Exception {
    KieServerUtil.deleteDocumentStorageFolder();
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), marshallingFormat, client.getClassLoader());
    DocumentInstance documentInstance = DocumentInstance.builder().name("test file.txt").size(50).content("test content".getBytes()).lastModified(new Date()).build();
    String documentEntity = marshaller.marshall(documentInstance);
    Map<String, Object> empty = new HashMap<>();
    Response response = null;
    try {
        // create document
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI, empty));
        logger.info("[POST] " + clientRequest.getUri());
        response = clientRequest.request(acceptHeadersByFormat.get(marshallingFormat)).post(createEntity(documentEntity));
        Assert.assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
        String documentId = response.readEntity(JaxbString.class).unwrap();
        assertNotNull(documentId);
        // list available documents without paging info
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(DOCUMENT_ID, documentId);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI, valuesMap));
        logger.info("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
        DocumentInstanceList docList = marshaller.unmarshall(response.readEntity(String.class), DocumentInstanceList.class);
        assertNotNull(docList);
        List<DocumentInstance> docs = docList.getItems();
        assertNotNull(docs);
        assertEquals(1, docs.size());
        DocumentInstance doc = docs.get(0);
        assertNotNull(doc);
        assertEquals(documentInstance.getName(), doc.getName());
        assertEquals(documentId, doc.getIdentifier());
        // download document content
        valuesMap = new HashMap<String, Object>();
        valuesMap.put(DOCUMENT_ID, documentId);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI + "/" + DOCUMENT_INSTANCE_CONTENT_GET_URI, valuesMap));
        logger.info("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).get();
        Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
        String contentDisposition = response.getHeaderString("Content-Disposition");
        assertTrue(contentDisposition.contains(documentInstance.getName()));
        byte[] content = response.readEntity(byte[].class);
        assertNotNull(content);
        String stringContent = new String(content);
        assertEquals("test content", stringContent);
        response.close();
        // delete document
        valuesMap = new HashMap<String, Object>();
        valuesMap.put(DOCUMENT_ID, documentId);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI + "/" + DOCUMENT_INSTANCE_DELETE_URI, valuesMap));
        logger.info("[DELETE] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).delete();
        int noContentStatusCode = Response.Status.NO_CONTENT.getStatusCode();
        int okStatusCode = Response.Status.OK.getStatusCode();
        assertTrue("Wrong status code returned: " + response.getStatus(), response.getStatus() == noContentStatusCode || response.getStatus() == okStatusCode);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : JaxbString(org.kie.server.api.model.type.JaxbString) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbString(org.kie.server.api.model.type.JaxbString) Date(java.util.Date) Response(javax.ws.rs.core.Response) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) BeforeClass(org.junit.BeforeClass) WebTarget(javax.ws.rs.client.WebTarget) DocumentInstanceList(org.kie.server.api.model.instance.DocumentInstanceList) Test(org.junit.Test)

Example 37 with Marshaller

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

the class ProcessServiceRestOnlyIntegrationTest method testNodeInstancesWhichBelongsToAProcess.

@Test
public void testNodeInstancesWhichBelongsToAProcess() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find node instances of process instance which is deployed in the given container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, pid);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_NODE_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        NodeInstanceList nodeInstanceList = marshaller.unmarshall(response.readEntity(String.class), NodeInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(nodeInstanceList.getItems()).hasSize(3);
        response.close();
        // find node instances of non-existing process instance
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, "-1");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCES_NODE_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        nodeInstanceList = marshaller.unmarshall(response.readEntity(String.class), NodeInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(nodeInstanceList.getItems()).isEmpty();
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) WebTarget(javax.ws.rs.client.WebTarget) NodeInstanceList(org.kie.server.api.model.instance.NodeInstanceList) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 38 with Marshaller

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

the class ProcessServiceRestOnlyIntegrationTest method testProcessVariablesWhichBelongsToAContainer.

@Test
public void testProcessVariablesWhichBelongsToAContainer() {
    Map<String, Object> valuesMap = new HashMap<String, Object>();
    valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
    valuesMap.put(RestURI.PROCESS_ID, PROCESS_ID_USERTASK);
    Response response = null;
    try {
        // start process instance
        WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + START_PROCESS_POST_URI, valuesMap));
        logger.debug("[POST] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).post(createEntity(""));
        assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode());
        Long pid = response.readEntity(JaxbLong.class).unwrap();
        assertThat(pid).isNotNull();
        response.close();
        // find process instance variables which belong to a process in a deployed container
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, pid);
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        Marshaller marshaller = MarshallerFactory.getMarshaller(marshallingFormat, Thread.currentThread().getContextClassLoader());
        VariableInstanceList variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.getItems()).hasSize(1);
        response.close();
        // find process instance variables of non-existing process instance
        valuesMap.clear();
        valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID);
        valuesMap.put(PROCESS_INST_ID, "-1");
        clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), PROCESS_URI + "/" + PROCESS_INSTANCE_VAR_INSTANCES_GET_URI, valuesMap));
        logger.debug("[GET] " + clientRequest.getUri());
        response = clientRequest.request(getMediaType()).get();
        variableInstanceList = marshaller.unmarshall(response.readEntity(String.class), VariableInstanceList.class);
        assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
        assertThat(variableInstanceList.getItems()).isEmpty();
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Marshaller(org.kie.server.api.marshalling.Marshaller) HashMap(java.util.HashMap) JaxbLong(org.kie.server.api.model.type.JaxbLong) VariableInstanceList(org.kie.server.api.model.instance.VariableInstanceList) WebTarget(javax.ws.rs.client.WebTarget) JaxbLong(org.kie.server.api.model.type.JaxbLong) Test(org.junit.Test)

Example 39 with Marshaller

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

the class DroolsCommandNestedPojoMarshallingTest method testXStream.

@Test
public void testXStream() {
    Marshaller marshaller = marshallerBuilder.build(getCustomClasses(), MarshallingFormat.XSTREAM, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestCommand(), xstreamExpectedPayload);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) Test(org.junit.Test)

Example 40 with Marshaller

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

the class DroolsCommandNestedPojoMarshallingTest method testJSON.

@Test
public void testJSON() {
    Marshaller marshaller = marshallerBuilder.build(getCustomClasses(), MarshallingFormat.JSON, getClass().getClassLoader());
    verifyMarshallingRoundTrip(marshaller, createTestCommand(), jsonExpectedPayload);
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) 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