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();
}
}
}
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();
}
}
}
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();
}
}
}
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);
}
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);
}
Aggregations