Search in sources :

Example 6 with Model

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());
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 7 with Model

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());
        }
    }
}
Also used : Model(org.activiti.engine.repository.Model) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

Example 8 with Model

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
            }
        }
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Calendar(java.util.Calendar) Model(org.activiti.engine.repository.Model)

Example 9 with Model

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
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Model(org.activiti.engine.repository.Model)

Example 10 with Model

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
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Model(org.activiti.engine.repository.Model) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Aggregations

Model (org.activiti.engine.repository.Model)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 ModelQuery (org.activiti.engine.repository.ModelQuery)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Calendar (java.util.Calendar)6 Deployment (org.activiti.engine.test.Deployment)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 InputStream (java.io.InputStream)5 HttpGet (org.apache.http.client.methods.HttpGet)5 HttpPut (org.apache.http.client.methods.HttpPut)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 ActivitiException (org.activiti.engine.ActivitiException)4 StringEntity (org.apache.http.entity.StringEntity)4 Button (com.vaadin.ui.Button)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3