use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class TableResourceTest method testGetTables.
/**
* Test getting tables. GET management/tables
*/
public void testGetTables() throws Exception {
Map<String, Long> tableCounts = managementService.getTableCount();
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLES_COLLECTION)), HttpStatus.SC_OK);
// Check table array
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertTrue(responseNode.isArray());
assertEquals(tableCounts.size(), responseNode.size());
for (int i = 0; i < responseNode.size(); i++) {
ObjectNode table = (ObjectNode) responseNode.get(i);
assertNotNull(table.get("name").textValue());
assertNotNull(table.get("count").longValue());
assertTrue(table.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, table.get("name").textValue())));
assertEquals(((Long) tableCounts.get(table.get("name").textValue())).longValue(), table.get("count").longValue());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class DeploymentCollectionResourceTest method testGetDeployments.
/**
* Test getting deployments.
* GET repository/deployments
*/
public void testGetDeployments() throws Exception {
try {
// Alter time to ensure different deployTimes
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DAY_OF_MONTH, -1);
processEngineConfiguration.getClock().setCurrentTime(yesterday.getTime());
Deployment firstDeployment = repositoryService.createDeployment().name("Deployment 1").category("DEF").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml").deploy();
processEngineConfiguration.getClock().setCurrentTime(Calendar.getInstance().getTime());
Deployment secondDeployment = repositoryService.createDeployment().name("Deployment 2").category("ABC").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml").tenantId("myTenant").deploy();
String baseUrl = RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION);
assertResultsPresentInDataResponse(baseUrl, firstDeployment.getId(), secondDeployment.getId());
// Check name filtering
String url = baseUrl + "?name=" + encode("Deployment 1");
assertResultsPresentInDataResponse(url, firstDeployment.getId());
// Check name-like filtering
url = baseUrl + "?nameLike=" + encode("%ment 2");
assertResultsPresentInDataResponse(url, secondDeployment.getId());
// Check category filtering
url = baseUrl + "?category=DEF";
assertResultsPresentInDataResponse(url, firstDeployment.getId());
// Check category-not-equals filtering
url = baseUrl + "?categoryNotEquals=DEF";
assertResultsPresentInDataResponse(url, secondDeployment.getId());
// Check tenantId filtering
url = baseUrl + "?tenantId=myTenant";
assertResultsPresentInDataResponse(url, secondDeployment.getId());
// Check tenantId filtering
url = baseUrl + "?tenantId=unexistingTenant";
assertResultsPresentInDataResponse(url);
// Check tenantId like filtering
url = baseUrl + "?tenantIdLike=" + encode("%enant");
assertResultsPresentInDataResponse(url, secondDeployment.getId());
// Check without tenantId filtering
url = baseUrl + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, firstDeployment.getId());
// Check ordering by name
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=name&order=asc"), HttpStatus.SC_OK);
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(2L, dataNode.size());
assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue());
assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue());
// Check ordering by deploy time
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc"), HttpStatus.SC_OK);
dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(2L, dataNode.size());
assertEquals(firstDeployment.getId(), dataNode.get(0).get("id").textValue());
assertEquals(secondDeployment.getId(), dataNode.get(1).get("id").textValue());
// Check ordering by tenantId
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=tenantId&order=desc"), HttpStatus.SC_OK);
dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(2L, dataNode.size());
assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue());
assertEquals(firstDeployment.getId(), dataNode.get(1).get("id").textValue());
// Check paging
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION) + "?sort=deployTime&order=asc&start=1&size=1"), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
dataNode = responseNode.get("data");
assertEquals(1L, dataNode.size());
assertEquals(secondDeployment.getId(), dataNode.get(0).get("id").textValue());
assertEquals(2L, responseNode.get("total").longValue());
assertEquals(1L, responseNode.get("start").longValue());
assertEquals(1L, responseNode.get("size").longValue());
} finally {
// Always cleanup any created deployments, even if the test failed
List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
for (Deployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class DeploymentResourceTest method testPostNewDeploymentBPMNFile.
/**
* Test deploying singe bpmn-file.
* POST repository/deployments
*/
public void testPostNewDeploymentBPMNFile() throws Exception {
try {
// Upload a valid BPMN-file using multipart-data
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("oneTaskProcess.bpmn20.xml", "application/xml", ReflectUtil.getResourceAsStream("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"), null));
CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
// Check deployment
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
String deploymentId = responseNode.get("id").textValue();
String name = responseNode.get("name").textValue();
String category = responseNode.get("category").textValue();
String deployTime = responseNode.get("deploymentTime").textValue();
String url = responseNode.get("url").textValue();
String tenantId = responseNode.get("tenantId").textValue();
assertEquals("", tenantId);
assertNotNull(deploymentId);
assertEquals(1L, repositoryService.createDeploymentQuery().deploymentId(deploymentId).count());
assertNotNull(name);
assertEquals("oneTaskProcess.bpmn20.xml", name);
assertNotNull(url);
assertTrue(url.endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
// No deployment-category should have been set
assertNull(category);
assertNotNull(deployTime);
// Check if process is actually deployed in the deployment
List<String> resources = repositoryService.getDeploymentResourceNames(deploymentId);
assertEquals(1L, resources.size());
assertEquals("oneTaskProcess.bpmn20.xml", resources.get(0));
assertEquals(1L, repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).count());
} finally {
// Always cleanup any created deployments, even if the test failed
List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
for (Deployment deployment : deployments) {
repositoryService.deleteDeployment(deployment.getId(), true);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class UserResourceTest method testUpdateUserNullFields.
/**
* Test updating a single user passing in no fields in the json, user should remain unchanged.
*/
public void testUpdateUserNullFields() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
taskUpdateRequest.putNull("firstName");
taskUpdateRequest.putNull("lastName");
taskUpdateRequest.putNull("email");
taskUpdateRequest.putNull("password");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testuser", responseNode.get("id").textValue());
assertTrue(responseNode.get("firstName").isNull());
assertTrue(responseNode.get("lastName").isNull());
assertTrue(responseNode.get("email").isNull());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));
// Check user is updated in activiti
newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
assertNull(newUser.getLastName());
assertNull(newUser.getFirstName());
assertNull(newUser.getEmail());
} finally {
// Delete user after test fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class UserResourceTest method testUpdateUserNoFields.
/**
* Test updating a single user passing in no fields in the json, user should remain unchanged.
*/
public void testUpdateUserNoFields() throws Exception {
User savedUser = null;
try {
User newUser = identityService.newUser("testuser");
newUser.setFirstName("Fred");
newUser.setLastName("McDonald");
newUser.setEmail("no-reply@activiti.org");
identityService.saveUser(newUser);
savedUser = newUser;
ObjectNode taskUpdateRequest = objectMapper.createObjectNode();
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId()));
httpPut.setEntity(new StringEntity(taskUpdateRequest.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("testuser", responseNode.get("id").textValue());
assertEquals("Fred", responseNode.get("firstName").textValue());
assertEquals("McDonald", responseNode.get("lastName").textValue());
assertEquals("no-reply@activiti.org", responseNode.get("email").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_USER, newUser.getId())));
// Check user is updated in activiti
newUser = identityService.createUserQuery().userId(newUser.getId()).singleResult();
assertEquals("McDonald", newUser.getLastName());
assertEquals("Fred", newUser.getFirstName());
assertEquals("no-reply@activiti.org", newUser.getEmail());
assertNull(newUser.getPassword());
} finally {
// Delete user after test fails
if (savedUser != null) {
identityService.deleteUser(savedUser.getId());
}
}
}
Aggregations