public class ModelResourceTest extends BaseSpringRestTestCase {
@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
}
}
}