Search in sources :

Example 16 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelResourceSourceTest method testSetModelEditorSource.

public void testSetModelEditorSource() throws Exception {
    Model model = null;
    try {
        model = repositoryService.newModel();
        model.setName("Model name");
        repositoryService.saveModel(model);
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
        httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new editor source".getBytes()), null));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
        assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId())));
    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
        // Ignore, model might not be created
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.activiti.engine.repository.Model) HttpPut(org.apache.http.client.methods.HttpPut)

Example 17 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelQueryEscapeClauseTest method setUp.

@Override
protected void setUp() throws Exception {
    Model model = repositoryService.newModel();
    model.setTenantId("mytenant%");
    model.setName("my model%");
    model.setKey("someKey1");
    model.setCategory("test%");
    repositoryService.saveModel(model);
    modelOneId = model.getId();
    model = repositoryService.newModel();
    model.setTenantId("mytenant_");
    model.setName("my model_");
    model.setKey("someKey2");
    model.setCategory("test_");
    repositoryService.saveModel(model);
    modelTwoId = model.getId();
    repositoryService.addModelEditorSource(modelOneId, "bytes".getBytes("utf-8"));
    repositoryService.addModelEditorSource(modelTwoId, "bytes".getBytes("utf-8"));
    super.setUp();
}
Also used : Model(org.activiti.engine.repository.Model)

Example 18 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelQueryEscapeClauseTest method testQueryByCategoryLike.

public void testQueryByCategoryLike() throws Exception {
    ModelQuery query = repositoryService.createModelQuery().modelCategoryLike("%\\%%");
    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().modelCategoryLike("%\\_%");
    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 19 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 20 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)

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