}
}
@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
}
}
}