use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelQueryEscapeClauseTest method testQueryByTenantIdLike.
public void testQueryByTenantIdLike() throws Exception {
ModelQuery query = repositoryService.createModelQuery().modelTenantIdLike("%\\%%");
Model model = query.singleResult();
assertNotNull(model);
assertEquals("someKey1", model.getKey());
assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
assertEquals(1, query.list().size());
assertEquals(1, query.count());
query = repositoryService.createModelQuery().modelTenantIdLike("%\\_%");
model = query.singleResult();
assertNotNull(model);
assertEquals("someKey2", model.getKey());
assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
assertEquals(1, query.list().size());
assertEquals(1, query.count());
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelEventsTest method testModelEvents.
/**
* Test create, update and delete events of model entities.
*/
public void testModelEvents() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("My model");
model.setKey("key");
repositoryService.saveModel(model);
// Check create event
assertEquals(2, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_CREATED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
assertEquals(ActivitiEventType.ENTITY_INITIALIZED, listener.getEventsReceived().get(1).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(1)).getEntity()).getId());
listener.clearEventsReceived();
// Update model
model = repositoryService.getModel(model.getId());
model.setName("Updated");
repositoryService.saveModel(model);
assertEquals(1, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
listener.clearEventsReceived();
// Test additional update-methods (source and extra-source)
repositoryService.addModelEditorSource(model.getId(), "test".getBytes());
repositoryService.addModelEditorSourceExtra(model.getId(), "test extra".getBytes());
assertEquals(2, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(1).getType());
listener.clearEventsReceived();
// Delete model events
repositoryService.deleteModel(model.getId());
assertEquals(1, listener.getEventsReceived().size());
assertEquals(ActivitiEventType.ENTITY_DELETED, listener.getEventsReceived().get(0).getType());
assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
listener.clearEventsReceived();
} finally {
if (model != null && repositoryService.getModel(model.getId()) != null) {
repositoryService.deleteModel(model.getId());
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceTest method testDeleteModel.
public void testDeleteModel() 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);
repositoryService.saveModel(model);
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
// Check if the model is really gone
assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());
model = null;
} finally {
if (model != null) {
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 ModelResourceSourceTest method testGetModelEditorSourceNoSource.
public void testGetModelEditorSourceNoSource() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("Model name");
repositoryService.saveModel(model);
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
} 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 ModelResourceSourceTest method testGetModelEditorSourceExtra.
public void testGetModelEditorSourceExtra() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("Model name");
repositoryService.saveModel(model);
repositoryService.addModelEditorSourceExtra(model.getId(), "This is the extra editor source".getBytes());
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
// Check "OK" status
assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
assertEquals("This is the extra editor source", IOUtils.toString(response.getEntity().getContent()));
closeResponse(response);
} finally {
try {
repositoryService.deleteModel(model.getId());
} catch (Throwable ignore) {
// Ignore, model might not be created
}
}
}
Aggregations