public class ModelCollectionResourceTest extends BaseSpringRestTestCase {
@Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
public void testGetModels() throws Exception {
// Create 2 models
Model model1 = null;
Model model2 = null;
try {
model1 = repositoryService.newModel();
model1.setCategory("Model category");
model1.setKey("Model key");
model1.setMetaInfo("Model metainfo");
model1.setName("Model name");
model1.setVersion(2);
model1.setDeploymentId(deploymentId);
repositoryService.saveModel(model1);
model2 = repositoryService.newModel();
model2.setCategory("Another category");
model2.setKey("Another key");
model2.setMetaInfo("Another metainfo");
model2.setName("Another name");
model2.setVersion(3);
repositoryService.saveModel(model2);
// Try filter-less, should return all models
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION);
assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());
// Filter based on id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?id=" + model1.getId();
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on category
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?category=" + encode("Another category");
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on category like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryLike=" + encode("Mode%");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on category not equals
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryNotEquals=" + encode("Another category");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on name
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?name=" + encode("Another name");
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on name like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?nameLike=" + encode("%del name");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on key
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on version
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?version=3";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on deploymentId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deploymentId=" + deploymentId;
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on deployed=true
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=true";
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on deployed=false
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=false";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on latestVersion
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key") + "&latestVersion=true";
// Make sure both models have same key
model2 = repositoryService.createModelQuery().modelId(model2.getId()).singleResult();
model2.setKey("Model key");
repositoryService.saveModel(model2);
assertResultsPresentInDataResponse(url, model2.getId());
// Filter without tenant ID, before tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());
// Set tenant ID
model1 = repositoryService.getModel(model1.getId());
model1.setTenantId("myTenant");
repositoryService.saveModel(model1);
// Filter without tenant ID, after tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on tenantId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=myTenant";
assertResultsPresentInDataResponse(url, model1.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=anotherTenant";
assertResultsPresentInDataResponse(url);
// Filter based on tenantId like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=" + encode("%enant");
assertResultsPresentInDataResponse(url, model1.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=anotherTenant";
assertResultsPresentInDataResponse(url);
} finally {
if(model1 != null) {
try {
repositoryService.deleteModel(model1.getId());
} catch(Throwable ignore) { }
}
if(model2 != null) {
try {
repositoryService.deleteModel(model2.getId());
} catch(Throwable ignore) { }
}
}
}