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));
}
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();
}
}
Aggregations