Search in sources :

Example 1 with TaskTestMapper

use of pro.taskana.mappings.TaskTestMapper in project taskana by Taskana.

the class CreateTaskAccTest method testCreateSimpleTaskWithCustomAttributes.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testCreateSimpleTaskWithCustomAttributes() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    Map<String, String> customAttributesForCreate = createSimpleCustomProperties(13);
    newTask.setCustomAttributes(customAttributesForCreate);
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask);
    assertEquals("T-Vertragstermin VERA", createdTask.getName());
    assertEquals("1234567", createdTask.getPrimaryObjRef().getValue());
    assertNotNull(createdTask.getCreated());
    assertNotNull(createdTask.getModified());
    assertNotNull(createdTask.getBusinessProcessId());
    assertEquals(null, createdTask.getClaimed());
    assertEquals(null, createdTask.getCompleted());
    assertEquals(createdTask.getCreated(), createdTask.getModified());
    assertEquals(createdTask.getCreated(), createdTask.getPlanned());
    assertEquals(TaskState.READY, createdTask.getState());
    assertEquals(null, createdTask.getParentBusinessProcessId());
    assertEquals(2, createdTask.getPriority());
    assertEquals(false, createdTask.isRead());
    assertEquals(false, createdTask.isTransferred());
    // verify that the database content is as expected
    TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest((TaskanaEngineImpl) taskanaEngine);
    try {
        SqlSession session = engineProxy.getSqlSession();
        Configuration config = session.getConfiguration();
        if (!config.hasMapper(TaskTestMapper.class)) {
            config.addMapper(TaskTestMapper.class);
        }
        TaskTestMapper mapper = session.getMapper(TaskTestMapper.class);
        engineProxy.openConnection();
        String customProperties = mapper.getCustomAttributesAsString(createdTask.getId());
        assertTrue(customProperties.contains("\"Property_13\":\"Property Value of Property_13\""));
        assertTrue(customProperties.contains("\"Property_12\":\"Property Value of Property_12\""));
        assertTrue(customProperties.contains("\"Property_11\":\"Property Value of Property_11\""));
        assertTrue(customProperties.contains("\"Property_10\":\"Property Value of Property_10\""));
        assertTrue(customProperties.contains("\"Property_9\":\"Property Value of Property_9\""));
        assertTrue(customProperties.contains("\"Property_8\":\"Property Value of Property_8\""));
        assertTrue(customProperties.contains("\"Property_7\":\"Property Value of Property_7\""));
        assertTrue(customProperties.contains("\"Property_6\":\"Property Value of Property_6\""));
        assertTrue(customProperties.contains("\"Property_5\":\"Property Value of Property_5\""));
        assertTrue(customProperties.contains("\"Property_4\":\"Property Value of Property_4\""));
        assertTrue(customProperties.contains("\"Property_3\":\"Property Value of Property_3\""));
        assertTrue(customProperties.contains("\"Property_2\":\"Property Value of Property_2\""));
        assertTrue(customProperties.contains("\"Property_1\":\"Property Value of Property_1\""));
    } finally {
        engineProxy.returnConnection();
    }
    // verify that the map is correctly retrieved from the database
    Task retrievedTask = taskService.getTask(createdTask.getId());
    Map<String, String> customAttributesFromDb = retrievedTask.getCustomAttributes();
    assertNotNull(customAttributesFromDb);
    assertTrue(customAttributesFromDb.equals(customAttributesForCreate));
}
Also used : Task(pro.taskana.Task) SqlSession(org.apache.ibatis.session.SqlSession) Configuration(org.apache.ibatis.session.Configuration) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) TaskTestMapper(pro.taskana.mappings.TaskTestMapper) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 2 with TaskTestMapper

use of pro.taskana.mappings.TaskTestMapper in project taskana by Taskana.

the class QueryTasksAccTest method testQueryTaskByCustomAttributes.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testQueryTaskByCustomAttributes() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    newTask.setClassificationKey("T2100");
    // about 1 Meg
    Map<String, String> customAttributesForCreate = createSimpleCustomProperties(20000);
    newTask.setCustomAttributes(customAttributesForCreate);
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask);
    // query the task by custom attributes
    TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest((TaskanaEngineImpl) taskanaEngine);
    try {
        SqlSession session = engineProxy.getSqlSession();
        Configuration config = session.getConfiguration();
        if (!config.hasMapper(TaskTestMapper.class)) {
            config.addMapper(TaskTestMapper.class);
        }
        TaskTestMapper mapper = session.getMapper(TaskTestMapper.class);
        engineProxy.openConnection();
        List<TaskImpl> queryResult = mapper.selectTasksByCustomAttributeLike("%Property Value of Property_1339%");
        assertTrue(queryResult.size() == 1);
        Task retrievedTask = queryResult.get(0);
        assertTrue(createdTask.getId().equals(retrievedTask.getId()));
        // verify that the map is correctly retrieved from the database
        Map<String, String> customAttributesFromDb = retrievedTask.getCustomAttributes();
        assertNotNull(customAttributesFromDb);
        assertTrue(customAttributesForCreate.equals(customAttributesFromDb));
    } finally {
        engineProxy.returnConnection();
    }
}
Also used : Task(pro.taskana.Task) SqlSession(org.apache.ibatis.session.SqlSession) Configuration(org.apache.ibatis.session.Configuration) TaskService(pro.taskana.TaskService) TaskImpl(pro.taskana.impl.TaskImpl) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) TaskTestMapper(pro.taskana.mappings.TaskTestMapper) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

AbstractAccTest (acceptance.AbstractAccTest)2 Configuration (org.apache.ibatis.session.Configuration)2 SqlSession (org.apache.ibatis.session.SqlSession)2 Test (org.junit.Test)2 Task (pro.taskana.Task)2 TaskService (pro.taskana.TaskService)2 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)2 TaskTestMapper (pro.taskana.mappings.TaskTestMapper)2 WithAccessId (pro.taskana.security.WithAccessId)2 TaskImpl (pro.taskana.impl.TaskImpl)1