Closes #1984 - Refactor TaskCommentAccTests to use Test-API
This commit is contained in:
parent
03683ce3eb
commit
7ef02cfdcc
|
@ -0,0 +1,174 @@
|
|||
package acceptance.taskcomment.delete;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.api.exceptions.SystemException;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.exceptions.NotAuthorizedOnTaskCommentException;
|
||||
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
|
||||
import pro.taskana.task.api.exceptions.TaskNotFoundException;
|
||||
import pro.taskana.task.api.models.Task;
|
||||
import pro.taskana.task.api.models.TaskComment;
|
||||
import pro.taskana.testapi.DefaultTestEntities;
|
||||
import pro.taskana.testapi.TaskanaInject;
|
||||
import pro.taskana.testapi.TaskanaIntegrationTest;
|
||||
import pro.taskana.testapi.builder.TaskBuilder;
|
||||
import pro.taskana.testapi.builder.TaskCommentBuilder;
|
||||
import pro.taskana.testapi.builder.WorkbasketAccessItemBuilder;
|
||||
import pro.taskana.testapi.security.WithAccessId;
|
||||
import pro.taskana.workbasket.api.WorkbasketPermission;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.exceptions.NotAuthorizedOnWorkbasketException;
|
||||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
|
||||
@TaskanaIntegrationTest
|
||||
class DeleteTaskCommentAccTest {
|
||||
|
||||
@TaskanaInject TaskService taskService;
|
||||
@TaskanaInject ClassificationService classificationService;
|
||||
@TaskanaInject WorkbasketService workbasketService;
|
||||
@TaskanaInject TaskanaEngine taskanaEngine;
|
||||
|
||||
Classification defaultClassification;
|
||||
Workbasket defaultWorkbasket;
|
||||
Task task1;
|
||||
TaskComment comment1;
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@BeforeAll
|
||||
void setup() throws Exception {
|
||||
defaultClassification =
|
||||
DefaultTestEntities.defaultTestClassification().buildAndStore(classificationService);
|
||||
defaultWorkbasket =
|
||||
DefaultTestEntities.defaultTestWorkbasket().buildAndStore(workbasketService);
|
||||
WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
|
||||
.workbasketId(defaultWorkbasket.getId())
|
||||
.accessId("user-1-1")
|
||||
.permission(WorkbasketPermission.OPEN)
|
||||
.permission(WorkbasketPermission.READ)
|
||||
.permission(WorkbasketPermission.READTASKS)
|
||||
.permission(WorkbasketPermission.APPEND)
|
||||
.buildAndStore(workbasketService);
|
||||
task1 =
|
||||
TaskBuilder.newTask()
|
||||
.classificationSummary(defaultClassification.asSummary())
|
||||
.workbasketSummary(defaultWorkbasket.asSummary())
|
||||
.primaryObjRef(DefaultTestEntities.defaultTestObjectReference().build())
|
||||
.buildAndStore(taskService);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_DeleteTaskComment_For_TaskCommentId() throws Exception {
|
||||
comment1 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text1")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService);
|
||||
|
||||
taskService.deleteTaskComment(comment1.getId());
|
||||
|
||||
List<TaskComment> taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId());
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(0);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2", groups = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() throws Exception {
|
||||
comment1 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text1")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService, "user-1-1");
|
||||
ThrowingCallable call = () -> taskService.deleteTaskComment(comment1.getId());
|
||||
NotAuthorizedOnTaskCommentException e =
|
||||
catchThrowableOfType(call, NotAuthorizedOnTaskCommentException.class);
|
||||
assertThat(e.getTaskCommentId()).isEqualTo(comment1.getId());
|
||||
assertThat(e.getCurrentUserId()).isEqualTo(taskanaEngine.getCurrentUserContext().getUserid());
|
||||
|
||||
List<TaskComment> taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId());
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(1);
|
||||
|
||||
taskanaEngine.runAsAdmin(
|
||||
() -> {
|
||||
try {
|
||||
taskService.deleteTaskComment(comment1.getId());
|
||||
} catch (TaskCommentNotFoundException ex) {
|
||||
throw new SystemException("Cannot find task comment with id " + ex.getTaskCommentId());
|
||||
} catch (TaskNotFoundException ex) {
|
||||
throw new SystemException("Cannot find task comment with id " + ex.getTaskId());
|
||||
} catch (NotAuthorizedOnTaskCommentException ex) {
|
||||
throw new SystemException(
|
||||
"User "
|
||||
+ ex.getCurrentUserId()
|
||||
+ " not authorized on task comment "
|
||||
+ ex.getTaskCommentId());
|
||||
} catch (NotAuthorizedOnWorkbasketException ex) {
|
||||
throw new SystemException(
|
||||
"User "
|
||||
+ ex.getCurrentUserId()
|
||||
+ " not authorized on workbasket "
|
||||
+ ex.getWorkbasketId());
|
||||
}
|
||||
});
|
||||
List<TaskComment> taskCommentsAfterDeletionWithAdmin =
|
||||
taskService.getTaskComments(task1.getId());
|
||||
assertThat(taskCommentsAfterDeletionWithAdmin).hasSize(0);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@WithAccessId(user = "taskadmin")
|
||||
@TestTemplate
|
||||
void should_DeleteTaskComment_When_UserIsInAdministrativeRole() throws Exception {
|
||||
comment1 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text1")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService);
|
||||
taskService.deleteTaskComment(comment1.getId());
|
||||
|
||||
List<TaskComment> taskCommentsAfterDeletion = taskService.getTaskComments(task1.getId());
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(0);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_TaskCommentIdIsInvalid() throws Exception {
|
||||
assertThatThrownBy(() -> taskService.deleteTaskComment(""))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_TaskCommentIdIsNull() throws Exception {
|
||||
assertThatThrownBy(() -> taskService.deleteTaskComment(null))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_CommentIdDoesNotExist() throws Exception {
|
||||
|
||||
ThrowingCallable call = () -> taskService.deleteTaskComment("non existing task comment id");
|
||||
TaskCommentNotFoundException e = catchThrowableOfType(call, TaskCommentNotFoundException.class);
|
||||
assertThat(e.getTaskCommentId()).isEqualTo("non existing task comment id");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,488 @@
|
|||
package acceptance.taskcomment.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import pro.taskana.TaskanaConfiguration;
|
||||
import pro.taskana.classification.api.ClassificationService;
|
||||
import pro.taskana.classification.api.models.Classification;
|
||||
import pro.taskana.common.api.TimeInterval;
|
||||
import pro.taskana.task.api.TaskCommentQuery;
|
||||
import pro.taskana.task.api.TaskCommentQueryColumnName;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.Task;
|
||||
import pro.taskana.task.api.models.TaskComment;
|
||||
import pro.taskana.testapi.DefaultTestEntities;
|
||||
import pro.taskana.testapi.TaskanaConfigurationModifier;
|
||||
import pro.taskana.testapi.TaskanaInject;
|
||||
import pro.taskana.testapi.TaskanaIntegrationTest;
|
||||
import pro.taskana.testapi.builder.TaskBuilder;
|
||||
import pro.taskana.testapi.builder.TaskCommentBuilder;
|
||||
import pro.taskana.testapi.builder.WorkbasketAccessItemBuilder;
|
||||
import pro.taskana.testapi.security.WithAccessId;
|
||||
import pro.taskana.user.api.UserService;
|
||||
import pro.taskana.user.api.models.User;
|
||||
import pro.taskana.workbasket.api.WorkbasketPermission;
|
||||
import pro.taskana.workbasket.api.WorkbasketService;
|
||||
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
|
||||
import pro.taskana.workbasket.api.models.Workbasket;
|
||||
|
||||
@TaskanaIntegrationTest
|
||||
class QueryTaskCommentAccTest {
|
||||
|
||||
@TaskanaInject TaskService taskService;
|
||||
@TaskanaInject ClassificationService classificationService;
|
||||
@TaskanaInject WorkbasketService workbasketService;
|
||||
@TaskanaInject UserService userService;
|
||||
|
||||
Classification defaultClassification;
|
||||
Workbasket defaultWorkbasket;
|
||||
Task task1;
|
||||
TaskComment comment1;
|
||||
TaskComment comment2;
|
||||
TaskComment comment3;
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@BeforeAll
|
||||
void setup() throws Exception {
|
||||
|
||||
defaultClassification =
|
||||
DefaultTestEntities.defaultTestClassification().buildAndStore(classificationService);
|
||||
defaultWorkbasket =
|
||||
DefaultTestEntities.defaultTestWorkbasket().buildAndStore(workbasketService);
|
||||
WorkbasketAccessItemBuilder.newWorkbasketAccessItem()
|
||||
.workbasketId(defaultWorkbasket.getId())
|
||||
.accessId("user-1-1")
|
||||
.permission(WorkbasketPermission.OPEN)
|
||||
.permission(WorkbasketPermission.READ)
|
||||
.permission(WorkbasketPermission.READTASKS)
|
||||
.permission(WorkbasketPermission.APPEND)
|
||||
.buildAndStore(workbasketService);
|
||||
|
||||
task1 =
|
||||
TaskBuilder.newTask()
|
||||
.classificationSummary(defaultClassification.asSummary())
|
||||
.workbasketSummary(defaultWorkbasket.asSummary())
|
||||
.primaryObjRef(DefaultTestEntities.defaultTestObjectReference().build())
|
||||
.buildAndStore(taskService);
|
||||
|
||||
comment1 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text1")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService, "user-1-1");
|
||||
comment2 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text2")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService, "user-1-1");
|
||||
comment3 =
|
||||
TaskCommentBuilder.newTaskComment()
|
||||
.taskId(task1.getId())
|
||||
.textField("Text3")
|
||||
.created(Instant.now())
|
||||
.modified(Instant.now())
|
||||
.buildAndStore(taskService, "admin");
|
||||
List<TaskComment> taskComments = taskService.getTaskComments(task1.getId());
|
||||
assertThat(taskComments).hasSize(3);
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class FilterTaskComments {
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().idIn(comment1.getId(), comment2.getId()).list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TaskIdIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().taskIdIn(task1.getId()).list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().creatorIn("user-1-1").list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorNotIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().creatorNotIn("user-1-2").list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2")
|
||||
@Test
|
||||
void should_ThrowException_When_NotAuthorizedToReadTaskComments() {
|
||||
|
||||
ThrowingCallable call =
|
||||
() -> taskService.createTaskCommentQuery().taskIdIn(task1.getId()).list();
|
||||
|
||||
assertThatThrownBy(call).isInstanceOf(NotAuthorizedToQueryWorkbasketException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatedWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(5), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().createdWithin(timeInterval).list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatedNotWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().createdNotWithin(timeInterval).list();
|
||||
assertThat(comments).isEmpty();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_ModifiedWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().modifiedWithin(timeInterval).list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_ModifiedNotWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().modifiedNotWithin(timeInterval).list();
|
||||
assertThat(comments).isEmpty();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdLike() {
|
||||
String searchId = "%" + comment1.getId().substring(1, comment1.getId().length() - 2) + "%";
|
||||
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().idLike(searchId).list();
|
||||
assertThat(comments).hasSize(1);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdNotLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().idNotLike("%ABC-123456%").list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TextFieldLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().textFieldLike("%ext%").list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TextFieldNotLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().textFieldNotLike("%other%").list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorLike() {
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().creatorLike("%-1-%").list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorNotLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().creatorNotLike("%dmi%").list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class CountTaskComments {
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethod() {
|
||||
long count = taskService.createTaskCommentQuery().count();
|
||||
assertThat(count).isEqualTo(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethodAndCreatorIn() {
|
||||
long count = taskService.createTaskCommentQuery().creatorIn("admin").count();
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethodAndCreatorNotIn() {
|
||||
long count = taskService.createTaskCommentQuery().creatorNotIn("admin").count();
|
||||
assertThat(count).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class QueryColumnTaskComments {
|
||||
@WithAccessId(user = "admin")
|
||||
@BeforeAll
|
||||
void setup() throws Exception {
|
||||
User userWithName = userService.newUser();
|
||||
userWithName.setId("user-1-1");
|
||||
userWithName.setFirstName("Max");
|
||||
userWithName.setLastName("Mustermann");
|
||||
userWithName.setFullName("Max Mustermann");
|
||||
userService.createUser(userWithName);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@AfterAll
|
||||
void reset() throws Exception {
|
||||
userService.deleteUser("user-1-1");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnId() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.ID, null);
|
||||
assertThat(listedValues)
|
||||
.hasSize(3)
|
||||
.containsExactlyInAnyOrder(comment1.getId(), comment2.getId(), comment3.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnTaskId() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.TASK_ID, null);
|
||||
assertThat(listedValues).hasSize(1).containsExactly(comment1.getTaskId());
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnTextField() {
|
||||
List<String> listedValues =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.listValues(TaskCommentQueryColumnName.TEXT_FIELD, null);
|
||||
assertThat(listedValues)
|
||||
.hasSize(3)
|
||||
.containsExactlyInAnyOrder(
|
||||
comment1.getTextField(), comment2.getTextField(), comment3.getTextField());
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreator() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.CREATOR, null);
|
||||
assertThat(listedValues).hasSize(2).containsExactlyInAnyOrder("user-1-1", "admin");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreatorLongName() {
|
||||
List<String> listedValues =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.listValues(TaskCommentQueryColumnName.CREATOR_FULL_NAME, null);
|
||||
assertThat(listedValues).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreated() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.CREATED, null);
|
||||
assertThat(listedValues).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnModified() {
|
||||
List<String> listedValues =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.listValues(TaskCommentQueryColumnName.MODIFIED, null);
|
||||
assertThat(listedValues).hasSize(3);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class OffsetConstraintsTaskComments {
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ConfirmQueryListOffset_When_ProvidingOffsetAndLimit() {
|
||||
List<TaskComment> offsetAndLimitResult = taskService.createTaskCommentQuery().list(1, 2);
|
||||
List<TaskComment> regularResult = taskService.createTaskCommentQuery().list();
|
||||
|
||||
assertThat(offsetAndLimitResult).hasSize(2);
|
||||
assertThat(offsetAndLimitResult.get(0))
|
||||
.isNotEqualTo(regularResult.get(0))
|
||||
.isEqualTo(regularResult.get(1));
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnEmptyList_When_ProvidingWrongConstraints() {
|
||||
List<TaskComment> result = taskService.createTaskCommentQuery().list(0, 1000);
|
||||
assertThat(result).hasSize(3);
|
||||
|
||||
result = taskService.createTaskCommentQuery().list(100, 1000);
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class SingleResultTaskComments {
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ReturnSingleTaskComment_When_UsingSingleMethod() {
|
||||
TaskComment single =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.idIn(comment1.getId())
|
||||
.creatorIn("user-1-1")
|
||||
.single();
|
||||
|
||||
assertThat(single.getId()).isEqualTo(comment1.getId());
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() {
|
||||
TaskCommentQuery query = taskService.createTaskCommentQuery().creatorIn("user-1-1");
|
||||
assertThatThrownBy(query::single).isInstanceOf(TooManyResultsException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class CreatorFullNameWhenAdditionalUserInfoIsTrue implements TaskanaConfigurationModifier {
|
||||
|
||||
@TaskanaInject TaskService taskService;
|
||||
@TaskanaInject UserService userService;
|
||||
|
||||
@Override
|
||||
public TaskanaConfiguration.Builder modify(TaskanaConfiguration.Builder builder) {
|
||||
return builder.addAdditionalUserInfo(true);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@BeforeAll
|
||||
void setup() throws Exception {
|
||||
User userWithName = userService.newUser();
|
||||
userWithName.setId("user-1-1");
|
||||
userWithName.setFirstName("Max");
|
||||
userWithName.setLastName("Mustermann");
|
||||
userWithName.setFullName("Max Mustermann");
|
||||
userService.createUser(userWithName);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@AfterAll
|
||||
void reset() throws Exception {
|
||||
userService.deleteUser("user-1-1");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_SetCreatorFullName_When_PropertyEnabled() throws Exception {
|
||||
List<TaskComment> taskComments =
|
||||
taskService.createTaskCommentQuery().idIn(comment1.getId()).list();
|
||||
|
||||
String creatorFullName = userService.getUser(taskComments.get(0).getCreator()).getFullName();
|
||||
assertThat(creatorFullName).isNotNull();
|
||||
assertThat(taskComments.get(0))
|
||||
.extracting(TaskComment::getCreatorFullName)
|
||||
.isEqualTo(creatorFullName);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_SetCreatorFullNameToNull_When_NotExistingAsUserInDatabase() {
|
||||
List<TaskComment> taskComments =
|
||||
taskService.createTaskCommentQuery().idIn(comment3.getId()).list();
|
||||
|
||||
assertThat(taskComments).hasSize(1);
|
||||
assertThat(taskComments.get(0)).extracting(TaskComment::getCreatorFullName).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class CreatorFullNameWhenAdditionalUserInfoIsFalse implements TaskanaConfigurationModifier {
|
||||
@TaskanaInject TaskService taskService;
|
||||
|
||||
@Override
|
||||
public TaskanaConfiguration.Builder modify(TaskanaConfiguration.Builder builder) {
|
||||
return builder.addAdditionalUserInfo(false);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@BeforeAll
|
||||
void setup() throws Exception {
|
||||
User userWithName = userService.newUser();
|
||||
userWithName.setId("user-1-1");
|
||||
userWithName.setFirstName("Max");
|
||||
userWithName.setLastName("Mustermann");
|
||||
userWithName.setFullName("Max Mustermann");
|
||||
userService.createUser(userWithName);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@AfterAll
|
||||
void reset() throws Exception {
|
||||
userService.deleteUser("user-1-1");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_NotSetCreatorFullName_When_PropertyDisabled() throws Exception {
|
||||
List<TaskComment> taskComments =
|
||||
taskService.createTaskCommentQuery().idIn(comment1.getId()).list();
|
||||
|
||||
assertThat(taskComments.get(0)).extracting(TaskComment::getCreatorFullName).isNull();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
package acceptance.taskcomment.delete;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.util.List;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.test.security.JaasExtension;
|
||||
import pro.taskana.common.test.security.WithAccessId;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.exceptions.NotAuthorizedOnTaskCommentException;
|
||||
import pro.taskana.task.api.exceptions.TaskCommentNotFoundException;
|
||||
import pro.taskana.task.api.models.TaskComment;
|
||||
|
||||
@ExtendWith(JaasExtension.class)
|
||||
class DeleteTaskCommentAccTest extends AbstractAccTest {
|
||||
|
||||
DeleteTaskCommentAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_DeleteTaskComment_For_TaskCommentId() throws Exception {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
List<TaskComment> taskComments =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
|
||||
assertThat(taskComments).hasSize(2);
|
||||
|
||||
taskService.deleteTaskComment("TCI:000000000000000000000000000000000004");
|
||||
|
||||
// make sure the task comment was deleted
|
||||
List<TaskComment> taskCommentsAfterDeletion =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000001");
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(1);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2", groups = "user-1-1") // to read comments
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() throws Exception {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
List<TaskComment> taskComments =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskComments).hasSize(3);
|
||||
|
||||
ThrowingCallable lambda =
|
||||
() -> taskService.deleteTaskComment("TCI:000000000000000000000000000000000000");
|
||||
|
||||
assertThatThrownBy(lambda).isInstanceOf(NotAuthorizedOnTaskCommentException.class);
|
||||
|
||||
// make sure the task comment was not deleted
|
||||
List<TaskComment> taskCommentsAfterDeletion =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@WithAccessId(user = "taskadmin")
|
||||
@TestTemplate
|
||||
void should_DeleteTaskComment_When_NoExplicitPermissionsButUserIsInAdministrativeRole()
|
||||
throws Exception {
|
||||
|
||||
resetDb(false);
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
List<TaskComment> taskComments =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
|
||||
assertThat(taskComments).hasSize(2);
|
||||
|
||||
taskService.deleteTaskComment("TCI:000000000000000000000000000000000006");
|
||||
|
||||
// make sure the task comment was deleted
|
||||
List<TaskComment> taskCommentsAfterDeletion =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(1);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_TaskCommentIdIsInvalid() throws Exception {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
List<TaskComment> taskComments =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskComments).hasSize(3);
|
||||
|
||||
assertThatThrownBy(() -> taskService.deleteTaskComment(""))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
|
||||
assertThatThrownBy(() -> taskService.deleteTaskComment(null))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
|
||||
// make sure that no task comment was deleted
|
||||
List<TaskComment> taskCommentsAfterDeletion =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_FailToDeleteTaskComment_When_TaskCommentIsNotExisting() throws Exception {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
List<TaskComment> taskComments =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskComments).hasSize(3);
|
||||
|
||||
ThrowingCallable lambda = () -> taskService.deleteTaskComment("non existing task comment id");
|
||||
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
|
||||
|
||||
// make sure the task comment was not deleted
|
||||
List<TaskComment> taskCommentsAfterDeletion =
|
||||
taskService.getTaskComments("TKI:000000000000000000000000000000000000");
|
||||
assertThat(taskCommentsAfterDeletion).hasSize(3);
|
||||
}
|
||||
}
|
|
@ -1,343 +0,0 @@
|
|||
package acceptance.taskcomment.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import pro.taskana.TaskanaConfiguration;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.api.TimeInterval;
|
||||
import pro.taskana.common.test.security.JaasExtension;
|
||||
import pro.taskana.common.test.security.WithAccessId;
|
||||
import pro.taskana.task.api.TaskCommentQuery;
|
||||
import pro.taskana.task.api.TaskCommentQueryColumnName;
|
||||
import pro.taskana.task.api.models.TaskComment;
|
||||
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
|
||||
|
||||
/** Test for TaskComment queries. */
|
||||
@ExtendWith(JaasExtension.class)
|
||||
class QueryTaskCommentAccTest extends AbstractAccTest {
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.idIn(
|
||||
"TCI:000000000000000000000000000000000000",
|
||||
"TCI:000000000000000000000000000000000002")
|
||||
.list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TaskIdIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.taskIdIn("TKI:000000000000000000000000000000000000")
|
||||
.list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_ThrowException_When_NotAuthorizedToReadTaskComments() {
|
||||
|
||||
ThrowingCallable call =
|
||||
() ->
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.taskIdIn("TKI:000000000000000000000000000000000020")
|
||||
.list();
|
||||
|
||||
assertThatThrownBy(call).isInstanceOf(NotAuthorizedToQueryWorkbasketException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorIn() {
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().creatorIn("user-1-2").list();
|
||||
assertThat(comments).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatedWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().createdWithin(timeInterval).list();
|
||||
assertThat(comments).isEmpty();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_ModifiedWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().modifiedWithin(timeInterval).list();
|
||||
assertThat(comments).isEmpty();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorNotIn() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().creatorNotIn("user-1-2").list();
|
||||
assertThat(comments).hasSize(11);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatedNotWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().createdNotWithin(timeInterval).list();
|
||||
assertThat(comments).hasSize(13);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_ModiefiedNotWithin() {
|
||||
TimeInterval timeInterval = new TimeInterval(Instant.now().minusSeconds(10), Instant.now());
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().modifiedNotWithin(timeInterval).list();
|
||||
assertThat(comments).hasSize(13);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdLike() {
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().idLike("%000001%").list();
|
||||
assertThat(comments).hasSize(4);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TextFieldLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().textFieldLike("%other%").list();
|
||||
assertThat(comments).hasSize(6);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorLike() {
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().creatorLike("%1-1%").list();
|
||||
assertThat(comments).hasSize(10);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_IdNotLike() {
|
||||
List<TaskComment> comments = taskService.createTaskCommentQuery().idNotLike("%000001%").list();
|
||||
assertThat(comments).hasSize(9);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_TextFieldNotLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().textFieldNotLike("%other%").list();
|
||||
assertThat(comments).hasSize(7);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_FilterTaskComments_For_CreatorNotLike() {
|
||||
List<TaskComment> comments =
|
||||
taskService.createTaskCommentQuery().creatorNotLike("%1-1%").list();
|
||||
assertThat(comments).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnCountOfEvents_When_UsingCountMethod() {
|
||||
long count = taskService.createTaskCommentQuery().creatorIn("user-1-1").count();
|
||||
assertThat(count).isEqualTo(10);
|
||||
|
||||
count = taskService.createTaskCommentQuery().creatorNotIn("user-1-1").count();
|
||||
assertThat(count).isEqualTo(3);
|
||||
|
||||
count = taskService.createTaskCommentQuery().count();
|
||||
assertThat(count).isEqualTo(13);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnId() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.ID, null);
|
||||
assertThat(listedValues).hasSize(13);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnTaskId() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.TASK_ID, null);
|
||||
assertThat(listedValues).hasSize(7);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnTextField() {
|
||||
List<String> listedValues =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.listValues(TaskCommentQueryColumnName.TEXT_FIELD, null);
|
||||
assertThat(listedValues).hasSize(2);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreator() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.CREATOR, null);
|
||||
assertThat(listedValues).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreatorLongName() throws Exception {
|
||||
TaskanaConfiguration taskanaConfiguration =
|
||||
new TaskanaConfiguration.Builder(AbstractAccTest.taskanaConfiguration)
|
||||
.addAdditionalUserInfo(false)
|
||||
.build();
|
||||
TaskanaEngine taskanaEngine = TaskanaEngine.buildTaskanaEngine(taskanaConfiguration);
|
||||
List<String> listedValues =
|
||||
taskanaEngine
|
||||
.getTaskService()
|
||||
.createTaskCommentQuery()
|
||||
.listValues(TaskCommentQueryColumnName.CREATOR_FULL_NAME, null);
|
||||
assertThat(listedValues).hasSize(3);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnCreated() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.CREATED, null);
|
||||
assertThat(listedValues).hasSize(5);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnListedValues_For_QueryColumnModified() {
|
||||
List<String> listedValues =
|
||||
taskService.createTaskCommentQuery().listValues(TaskCommentQueryColumnName.MODIFIED, null);
|
||||
assertThat(listedValues).hasSize(7);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ConfirmQueryListOffset_When_ProvidingOffsetAndLimit() {
|
||||
List<TaskComment> offsetAndLimitResult = taskService.createTaskCommentQuery().list(1, 2);
|
||||
List<TaskComment> regularResult = taskService.createTaskCommentQuery().list();
|
||||
|
||||
assertThat(offsetAndLimitResult).hasSize(2);
|
||||
assertThat(offsetAndLimitResult.get(0))
|
||||
.isNotEqualTo(regularResult.get(0))
|
||||
.isEqualTo(regularResult.get(1));
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnEmptyList_When_ProvidingWrongConstraints() {
|
||||
List<TaskComment> result = taskService.createTaskCommentQuery().list(1, 1000);
|
||||
assertThat(result).hasSize(12);
|
||||
|
||||
result = taskService.createTaskCommentQuery().list(100, 1000);
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ReturnSingleTaskComment_When_UsingSingleMethod() {
|
||||
TaskComment single =
|
||||
taskService
|
||||
.createTaskCommentQuery()
|
||||
.taskIdIn("TKI:000000000000000000000000000000000000")
|
||||
.creatorIn("user-1-2")
|
||||
.single();
|
||||
|
||||
assertThat(single.getId()).isEqualTo("TCI:000000000000000000000000000000000001");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_ThrowException_When_SingleMethodRetrievesMoreThanOneEventFromDatabase() {
|
||||
TaskCommentQuery query = taskService.createTaskCommentQuery().creatorIn("user-1-1");
|
||||
assertThatThrownBy(query::single).isInstanceOf(TooManyResultsException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_SetTaskCreatorFullNameOfTaskComment_When_PropertyEnabled() throws Exception {
|
||||
TaskanaConfiguration taskanaConfiguration =
|
||||
new TaskanaConfiguration.Builder(AbstractAccTest.taskanaConfiguration)
|
||||
.addAdditionalUserInfo(true)
|
||||
.build();
|
||||
TaskanaEngine taskanaEngine = TaskanaEngine.buildTaskanaEngine(taskanaConfiguration);
|
||||
List<TaskComment> taskComments =
|
||||
taskanaEngine
|
||||
.getTaskService()
|
||||
.createTaskCommentQuery()
|
||||
.idIn("TCI:000000000000000000000000000000000000")
|
||||
.list();
|
||||
|
||||
assertThat(taskComments).hasSize(1);
|
||||
String creatorFullName =
|
||||
taskanaEngine.getUserService().getUser(taskComments.get(0).getCreator()).getFullName();
|
||||
assertThat(taskComments.get(0))
|
||||
.extracting(TaskComment::getCreatorFullName)
|
||||
.isEqualTo(creatorFullName);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1")
|
||||
@Test
|
||||
void should_NotSetTaskCreatorFullNameOfTaskComment_When_PropertyDisabled() throws Exception {
|
||||
TaskanaConfiguration taskanaConfiguration =
|
||||
new TaskanaConfiguration.Builder(AbstractAccTest.taskanaConfiguration)
|
||||
.addAdditionalUserInfo(false)
|
||||
.build();
|
||||
TaskanaEngine taskanaEngine = TaskanaEngine.buildTaskanaEngine(taskanaConfiguration);
|
||||
List<TaskComment> taskComments =
|
||||
taskanaEngine
|
||||
.getTaskService()
|
||||
.createTaskCommentQuery()
|
||||
.idIn("TCI:000000000000000000000000000000000000")
|
||||
.list();
|
||||
|
||||
assertThat(taskComments).hasSize(1);
|
||||
assertThat(taskComments.get(0)).extracting(TaskComment::getCreatorFullName).isNull();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void should_SetTaskCreatorFullNameOfTaskCommentToNull_When_NotExistingAsUserInDatabase()
|
||||
throws Exception {
|
||||
TaskanaConfiguration taskanaConfiguration =
|
||||
new TaskanaConfiguration.Builder(AbstractAccTest.taskanaConfiguration)
|
||||
.addAdditionalUserInfo(true)
|
||||
.build();
|
||||
TaskanaEngine taskanaEngine = TaskanaEngine.buildTaskanaEngine(taskanaConfiguration);
|
||||
List<TaskComment> taskComments =
|
||||
taskanaEngine
|
||||
.getTaskService()
|
||||
.createTaskCommentQuery()
|
||||
.idIn("TCI:000000000000000000000000000000000008")
|
||||
.list();
|
||||
|
||||
assertThat(taskComments).hasSize(1);
|
||||
assertThat(taskComments.get(0)).extracting(TaskComment::getCreatorFullName).isNull();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue