Search in sources :

Example 21 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class CreateTaskAccTest method testPrioDurationOfTaskFromAttachmentsAtCreate.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testPrioDurationOfTaskFromAttachmentsAtCreate() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    // prio 8, SL P7D
    newTask.setClassificationKey("L12010");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    newTask.addAttachment(createAttachment(// prio 99, SL P2000D
    "DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    newTask.addAttachment(createAttachment(// prio 1, SL P1D
    "L1060", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask.getId());
    assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    Task readTask = taskService.getTask(createdTask.getId());
    assertNotNull(readTask);
    assertThat(readTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    assertNotNull(readTask.getAttachments());
    assertEquals(2, readTask.getAttachments().size());
    assertNotNull(readTask.getAttachments().get(1).getCreated());
    assertNotNull(readTask.getAttachments().get(1).getModified());
    assertEquals(readTask.getAttachments().get(0).getCreated(), readTask.getAttachments().get(1).getModified());
    // assertNotNull(readTask.getAttachments().get(0).getClassification());
    assertNotNull(readTask.getAttachments().get(0).getObjectReference());
    assertTrue(readTask.getPriority() == 99);
    DaysToWorkingDaysConverter converter = DaysToWorkingDaysConverter.initialize(Collections.singletonList(new TimeIntervalColumnHeader(0)), Instant.now());
    long calendarDays = converter.convertWorkingDaysToDays(readTask.getPlanned(), 1);
    assertTrue(readTask.getDue().equals(readTask.getPlanned().plus(Duration.ofDays(calendarDays))));
}
Also used : DaysToWorkingDaysConverter(pro.taskana.impl.DaysToWorkingDaysConverter) Task(pro.taskana.Task) TaskService(pro.taskana.TaskService) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 22 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class CreateTaskAccTest method testCreateExternalTaskWithAttachment.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testCreateExternalTaskWithAttachment() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("L12010");
    Map<String, String> customAttributesForCreate = createSimpleCustomProperties(27);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", customAttributesForCreate));
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask.getId());
    assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    // verify that the database content is as expected
    TaskanaEngineProxyForTest engineProxy = new TaskanaEngineProxyForTest((TaskanaEngineImpl) taskanaEngine);
    try {
        SqlSession session = engineProxy.getSqlSession();
        AttachmentMapper mapper = session.getMapper(AttachmentMapper.class);
        engineProxy.openConnection();
        String customProperties = mapper.getCustomAttributesAsString(createdTask.getAttachments().get(0).getId());
        assertTrue(customProperties.contains("\"Property_26\":\"Property Value of Property_26\""));
        assertTrue(customProperties.contains("\"Property_25\":\"Property Value of Property_25\""));
        assertTrue(customProperties.contains("\"Property_21\":\"Property Value of Property_21\""));
        assertTrue(customProperties.contains("\"Property_19\":\"Property Value of Property_19\""));
        assertTrue(customProperties.contains("\"Property_16\":\"Property Value of Property_16\""));
        assertTrue(customProperties.contains("\"Property_12\":\"Property Value of Property_12\""));
        assertTrue(customProperties.contains("\"Property_11\":\"Property Value of Property_11\""));
        assertTrue(customProperties.contains("\"Property_7\":\"Property Value of Property_7\""));
        assertTrue(customProperties.contains("\"Property_6\":\"Property Value of Property_6\""));
    } finally {
        engineProxy.returnConnection();
    }
    Task readTask = taskService.getTask(createdTask.getId());
    assertNotNull(readTask);
    assertThat(readTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    assertNotNull(readTask.getAttachments());
    assertEquals(1, readTask.getAttachments().size());
    assertNotNull(readTask.getAttachments().get(0).getCreated());
    assertNotNull(readTask.getAttachments().get(0).getModified());
    assertEquals(readTask.getAttachments().get(0).getCreated(), readTask.getAttachments().get(0).getModified());
    assertNotNull(readTask.getAttachments().get(0).getClassificationSummary());
    assertNotNull(readTask.getAttachments().get(0).getObjectReference());
    // verify that the map is correctly retrieved from the database
    Map<String, String> customAttributesFromDb = readTask.getAttachments().get(0).getCustomAttributes();
    assertNotNull(customAttributesFromDb);
    assertTrue(customAttributesFromDb.equals(customAttributesForCreate));
}
Also used : Task(pro.taskana.Task) SqlSession(org.apache.ibatis.session.SqlSession) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 23 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class CreateTaskAccTest method testCreateExternalTaskWithMultipleAttachments.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testCreateExternalTaskWithMultipleAttachments() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("L12010");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask.getId());
    assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    Task readTask = taskService.getTask(createdTask.getId());
    assertNotNull(readTask);
    assertThat(readTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    assertNotNull(readTask.getAttachments());
    assertEquals(2, readTask.getAttachments().size());
    assertNotNull(readTask.getAttachments().get(1).getCreated());
    assertNotNull(readTask.getAttachments().get(1).getModified());
    assertEquals(readTask.getAttachments().get(0).getCreated(), readTask.getAttachments().get(1).getModified());
    // assertNotNull(readTask.getAttachments().get(0).getClassification());
    assertNotNull(readTask.getAttachments().get(0).getObjectReference());
}
Also used : Task(pro.taskana.Task) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 24 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class CreateTaskAccTest method testSetDomainFromWorkbasket.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testSetDomainFromWorkbasket() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
    TaskService taskService = taskanaEngine.getTaskService();
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket workbasket = workbasketService.getWorkbasket("USER_1_1", "DOMAIN_A");
    Task newTask = taskService.newTask("WBI:100000000000000000000000000000000006");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    Task createdTask = taskService.createTask(newTask);
    assertNotNull(createdTask);
    assertThat(createdTask.getCreator(), equalTo(CurrentUserContext.getUserid()));
    assertNotNull(createdTask.getDomain());
    assertEquals(workbasket.getDomain(), createdTask.getDomain());
}
Also used : Task(pro.taskana.Task) WorkbasketService(pro.taskana.WorkbasketService) TaskService(pro.taskana.TaskService) Workbasket(pro.taskana.Workbasket) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 25 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class CreateTaskAccTest method testThrowsExceptionIfMandatoryPrimaryObjectReferenceIsNotSetOrIncomplete.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testThrowsExceptionIfMandatoryPrimaryObjectReferenceIsNotSetOrIncomplete() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    // Exception
    newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Value is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    // Exception
    newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Type is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    // Exception
    newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-SystemInstances is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    // Exception
    newTask = taskService.newTask("USER_1_1", "DOMAIN_A");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-System is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    // Exception
    newTask = taskService.newTask("WBI:100000000000000000000000000000000006");
    newTask.setClassificationKey("T2100");
    newTask.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Company is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
}
Also used : Task(pro.taskana.Task) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

Test (org.junit.Test)216 WithAccessId (pro.taskana.security.WithAccessId)216 AbstractAccTest (acceptance.AbstractAccTest)201 TaskService (pro.taskana.TaskService)100 WorkbasketService (pro.taskana.WorkbasketService)78 Task (pro.taskana.Task)57 WorkbasketSummary (pro.taskana.WorkbasketSummary)51 TaskSummary (pro.taskana.TaskSummary)47 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)34 Workbasket (pro.taskana.Workbasket)23 Classification (pro.taskana.Classification)21 KeyDomain (pro.taskana.KeyDomain)19 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)19 ArrayList (java.util.ArrayList)17 Instant (java.time.Instant)16 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)16 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)15 Connection (java.sql.Connection)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 TimeInterval (pro.taskana.TimeInterval)8