use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testUpdateModel.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModel() throws Exception {
Model model = null;
try {
Calendar createTime = Calendar.getInstance();
createTime.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());
model = repositoryService.newModel();
model.setCategory("Model category");
model.setKey("Model key");
model.setMetaInfo("Model metainfo");
model.setName("Model name");
model.setVersion(2);
repositoryService.saveModel(model);
Calendar updateTime = Calendar.getInstance();
updateTime.set(Calendar.MILLISECOND, 0);
updateTime.add(Calendar.HOUR, 1);
processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());
// Create update request
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "Updated name");
requestNode.put("category", "Updated category");
requestNode.put("key", "Updated key");
requestNode.put("metaInfo", "Updated metainfo");
requestNode.put("deploymentId", deploymentId);
requestNode.put("version", 3);
requestNode.put("tenantId", "myTenant");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("Updated name", responseNode.get("name").textValue());
assertEquals("Updated key", responseNode.get("key").textValue());
assertEquals("Updated category", responseNode.get("category").textValue());
assertEquals(3, responseNode.get("version").intValue());
assertEquals("Updated metainfo", responseNode.get("metaInfo").textValue());
assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
assertEquals(model.getId(), responseNode.get("id").textValue());
assertEquals("myTenant", responseNode.get("tenantId").textValue());
assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testUpdateModelNoFields.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModelNoFields() throws Exception {
Model model = null;
try {
Calendar now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
model = repositoryService.newModel();
model.setCategory("Model category");
model.setKey("Model key");
model.setMetaInfo("Model metainfo");
model.setName("Model name");
model.setVersion(2);
model.setDeploymentId(deploymentId);
repositoryService.saveModel(model);
// Use empty request-node, nothing should be changed after update
ObjectNode requestNode = objectMapper.createObjectNode();
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("Model name", responseNode.get("name").textValue());
assertEquals("Model key", responseNode.get("key").textValue());
assertEquals("Model category", responseNode.get("category").textValue());
assertEquals(2, responseNode.get("version").intValue());
assertEquals("Model metainfo", responseNode.get("metaInfo").textValue());
assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
assertEquals(model.getId(), responseNode.get("id").textValue());
assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testGetModel.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetModel() throws Exception {
Model model = null;
try {
Calendar now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(now.getTime());
model = repositoryService.newModel();
model.setCategory("Model category");
model.setKey("Model key");
model.setMetaInfo("Model metainfo");
model.setName("Model name");
model.setVersion(2);
model.setDeploymentId(deploymentId);
model.setTenantId("myTenant");
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), "This is the editor source".getBytes());
repositoryService.addModelEditorSourceExtra(model.getId(), "This is the extra editor source".getBytes());
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("Model name", responseNode.get("name").textValue());
assertEquals("Model key", responseNode.get("key").textValue());
assertEquals("Model category", responseNode.get("category").textValue());
assertEquals(2, responseNode.get("version").intValue());
assertEquals("Model metainfo", responseNode.get("metaInfo").textValue());
assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
assertEquals(model.getId(), responseNode.get("id").textValue());
assertEquals("myTenant", responseNode.get("tenantId").textValue());
assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
assertTrue(responseNode.get("sourceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId())));
assertTrue(responseNode.get("sourceExtraUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId())));
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testUpdateModelOverrideWithNull.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModelOverrideWithNull() throws Exception {
Model model = null;
try {
Calendar createTime = Calendar.getInstance();
createTime.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());
model = repositoryService.newModel();
model.setCategory("Model category");
model.setKey("Model key");
model.setMetaInfo("Model metainfo");
model.setName("Model name");
model.setTenantId("myTenant");
model.setVersion(2);
repositoryService.saveModel(model);
Calendar updateTime = Calendar.getInstance();
updateTime.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());
// Create update request
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", (String) null);
requestNode.put("category", (String) null);
requestNode.put("key", (String) null);
requestNode.put("metaInfo", (String) null);
requestNode.put("deploymentId", (String) null);
requestNode.put("version", (String) null);
requestNode.put("tenantId", (String) null);
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertNull(responseNode.get("name").textValue());
assertNull(responseNode.get("key").textValue());
assertNull(responseNode.get("category").textValue());
assertNull(responseNode.get("version").textValue());
assertNull(responseNode.get("metaInfo").textValue());
assertNull(responseNode.get("deploymentId").textValue());
assertNull(responseNode.get("tenantId").textValue());
assertEquals(model.getId(), responseNode.get("id").textValue());
assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
model = repositoryService.getModel(model.getId());
assertNull(model.getName());
assertNull(model.getKey());
assertNull(model.getCategory());
assertNull(model.getMetaInfo());
assertNull(model.getDeploymentId());
assertEquals("", model.getTenantId());
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelCollectionResourceTest method testCreateModel.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateModel() throws Exception {
Model model = null;
try {
Calendar createTime = Calendar.getInstance();
createTime.set(Calendar.MILLISECOND, 0);
processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());
// Create create request
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "Model name");
requestNode.put("category", "Model category");
requestNode.put("key", "Model key");
requestNode.put("metaInfo", "Model metainfo");
requestNode.put("deploymentId", deploymentId);
requestNode.put("version", 2);
requestNode.put("tenantId", "myTenant");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("Model name", responseNode.get("name").textValue());
assertEquals("Model key", responseNode.get("key").textValue());
assertEquals("Model category", responseNode.get("category").textValue());
assertEquals(2, responseNode.get("version").intValue());
assertEquals("Model metainfo", responseNode.get("metaInfo").textValue());
assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
assertEquals("myTenant", responseNode.get("tenantId").textValue());
assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, responseNode.get("id").textValue())));
assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
model = repositoryService.createModelQuery().modelId(responseNode.get("id").textValue()).singleResult();
assertNotNull(model);
assertEquals("Model category", model.getCategory());
assertEquals("Model name", model.getName());
assertEquals("Model key", model.getKey());
assertEquals(deploymentId, model.getDeploymentId());
assertEquals("Model metainfo", model.getMetaInfo());
assertEquals("myTenant", model.getTenantId());
assertEquals(2, model.getVersion().intValue());
} finally {
if (model != null) {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
}
}
}
}
Aggregations