comments from Holger Hagen

This commit is contained in:
Jörg Heffner 2020-03-30 16:03:08 +02:00 committed by Holger Hagen
parent 636135bf1a
commit dffb139a82
13 changed files with 104 additions and 271 deletions

View File

@ -414,7 +414,6 @@ public interface TaskService {
/**
* Deletes the task comment with the given Id.
*
* @param taskId The task id where the comment is supposed to be attached to
* @param taskCommentId The id of the task comment to delete.
* @throws NotAuthorizedException If the current user has no authorization to delete a task
* comment or is not authorized to access the task.
@ -425,14 +424,13 @@ public interface TaskService {
* existing task.
* @throws InvalidArgumentException If the given taskCommentId is null or empty
*/
void deleteTaskComment(String taskId, String taskCommentId)
void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException;
/**
* Retrieves a task comment for a given taskCommentId.
*
* @param taskId The task id where the comment is supposed to be attached to
* @param taskCommentId The id of the task comment which should be retrieved
* @return the task comment identified by taskCommentId
* @throws TaskCommentNotFoundException If the given taskCommentId in the TaskComment does not
@ -443,7 +441,7 @@ public interface TaskService {
* existing task.
* @throws InvalidArgumentException If the given taskCommentId is null or empty
*/
TaskComment getTaskComment(String taskId, String taskCommentId)
TaskComment getTaskComment(String taskCommentId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException;

View File

@ -49,7 +49,6 @@ public interface TaskCommentMapper {
"<script> SELECT ID, TASK_ID, TEXT_FIELD, CREATOR, CREATED, MODIFIED"
+ " FROM TASK_COMMENT "
+ "WHERE ID = #{taskCommentId} "
+ "AND TASK_ID = #{taskId} "
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
+ "</script>")
@Results(
@ -62,5 +61,5 @@ public interface TaskCommentMapper {
@Result(property = "modified", column = "MODIFIED"),
})
TaskCommentImpl findById(
@Param("taskId") String taskId, @Param("taskCommentId") String taskCommentId);
@Param("taskCommentId") String taskCommentId);
}

View File

@ -73,7 +73,7 @@ class TaskCommentServiceImpl {
|| taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
TaskComment oldTaskComment =
getTaskComment(taskCommentImplToUpdate.getTaskId(), taskCommentImplToUpdate.getId());
getTaskComment(taskCommentImplToUpdate.getId());
checkModifiedHasNotChanged(oldTaskComment, taskCommentImplToUpdate);
@ -128,12 +128,12 @@ class TaskCommentServiceImpl {
return taskCommentImplToCreate;
}
void deleteTaskComment(String taskId, String taskCommentId)
void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException {
LOGGER.debug(
"entry to deleteTaskComment (taskId = {}, taskComment = {}", taskId, taskCommentId);
"entry to deleteTaskComment (taskComment = {}", taskCommentId);
String userId = CurrentUserContext.getUserid();
@ -141,7 +141,7 @@ class TaskCommentServiceImpl {
taskanaEngine.openConnection();
TaskComment taskCommentToDelete = getTaskComment(taskId, taskCommentId);
TaskComment taskCommentToDelete = getTaskComment(taskCommentId);
if (taskCommentToDelete.getCreator().equals(userId)
|| taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
@ -189,11 +189,11 @@ class TaskCommentServiceImpl {
}
}
TaskComment getTaskComment(String taskId, String taskCommentId)
TaskComment getTaskComment(String taskCommentId)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
LOGGER.debug("entry to getTaskComment (taskId= {}, taskCommentId = {})", taskId, taskCommentId);
LOGGER.debug("entry to getTaskComment (taskCommentId = {})", taskCommentId);
TaskCommentImpl result;
@ -203,14 +203,14 @@ class TaskCommentServiceImpl {
taskanaEngine.openConnection();
result = taskCommentMapper.findById(taskId, taskCommentId);
result = taskCommentMapper.findById(taskCommentId);
if (result == null) {
throw new TaskCommentNotFoundException(
taskCommentId,
String.format(
"TaskComment for taskId '%s' and taskCommentId '%s' was not found",
taskId, taskCommentId));
"TaskComment for taskCommentId '%s' was not found",
taskCommentId));
}
taskService.getTask(result.getTaskId());

View File

@ -614,17 +614,17 @@ public class TaskServiceImpl implements TaskService {
}
@Override
public void deleteTaskComment(String taskId, String taskCommentId)
public void deleteTaskComment(String taskCommentId)
throws NotAuthorizedException, TaskCommentNotFoundException, TaskNotFoundException,
InvalidArgumentException {
taskCommentService.deleteTaskComment(taskId, taskCommentId);
taskCommentService.deleteTaskComment(taskCommentId);
}
@Override
public TaskComment getTaskComment(String taskId, String taskCommentid)
public TaskComment getTaskComment(String taskCommentid)
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
return taskCommentService.getTaskComment(taskId, taskCommentid);
return taskCommentService.getTaskComment(taskCommentid);
}
@Override

View File

@ -27,7 +27,7 @@ public class CreateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskComment()
void should_CreateTaskComment_For_TaskComment()
throws TaskNotFoundException, NotAuthorizedException, InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
@ -52,7 +52,7 @@ public class CreateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testCreateTaskCommentForNullOrNonExistingTaskIdShouldFail() {
void should_FailToCreateTaskComment_When_TaskIdIsNullOrNonExisting() {
TaskService taskService = taskanaEngine.getTaskService();

View File

@ -29,7 +29,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteTaskComment()
void should_DeleteTaskComment_For_TaskCommentId()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
@ -40,7 +40,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
assertThat(taskComments).hasSize(2);
taskService.deleteTaskComment(
"TKI:000000000000000000000000000000000001", "TCI:000000000000000000000000000000000004");
"TCI:000000000000000000000000000000000004");
// make sure the task comment was deleted
List<TaskComment> taskCommentsAfterDeletion =
@ -52,7 +52,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_2",
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithNoAuthorizationShouldFail()
void should_FailToDeleteTaskComment_When_UserHasNoAuthorization()
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
@ -64,7 +64,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
ThrowingCallable lambda =
() ->
taskService.deleteTaskComment(
"TKI:000000000000000000000000000000000001",
"TCI:000000000000000000000000000000000005");
assertThatThrownBy(lambda).isInstanceOf(NotAuthorizedException.class);
@ -78,7 +78,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteTaskCommentWithInvalidTaskCommentIdShouldFail()
void should_FailToDeleteTaskComment_When_TaskCommentIdIsInvalid()
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
@ -87,16 +87,10 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
taskService.getTaskComments("TKI:000000000000000000000000000000000002");
assertThat(taskComments).hasSize(2);
assertThatThrownBy(() -> taskService.deleteTaskComment("", ""))
assertThatThrownBy(() -> taskService.deleteTaskComment(""))
.isInstanceOf(InvalidArgumentException.class);
assertThatThrownBy(() -> taskService.deleteTaskComment("", null))
.isInstanceOf(InvalidArgumentException.class);
assertThatThrownBy(() -> taskService.deleteTaskComment(null, ""))
.isInstanceOf(InvalidArgumentException.class);
assertThatThrownBy(() -> taskService.deleteTaskComment(null, null))
assertThatThrownBy(() -> taskService.deleteTaskComment(null))
.isInstanceOf(InvalidArgumentException.class);
// make sure that no task comment was deleted
@ -109,7 +103,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testDeleteNonExistingTaskCommentShouldFail()
void should_FailToDeleteTaskComment_When_TaskCommentIsNotExisting()
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
@ -119,7 +113,7 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest {
assertThat(taskComments).hasSize(2);
ThrowingCallable lambda =
() -> taskService.deleteTaskComment("invalidTaskId", "non existing task comment id");
() -> taskService.deleteTaskComment("non existing task comment id");
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
// make sure the task comment was not deleted

View File

@ -29,7 +29,7 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComments() throws NotAuthorizedException, TaskNotFoundException {
void should_ReturnTaskComments_For_TaskId() throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
@ -43,7 +43,7 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentsShouldReturnEmptyList()
void should_ReturnEmptyList_When_TaskCommentsDontExist()
throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
@ -55,7 +55,7 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskCommentsOfNotVisibleTaskShouldFail() {
void should_FailToReturnTaskComments_When_TaskIstNotVisible() {
TaskService taskService = taskanaEngine.getTaskService();
@ -70,15 +70,14 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskComment()
void should_ReturnTaskComment_For_TaskCommentId()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
TaskService taskService = taskanaEngine.getTaskService();
TaskComment taskComment =
taskService.getTaskComment(
"TKI:000000000000000000000000000000000002", "TCI:000000000000000000000000000000000007");
taskService.getTaskComment("TCI:000000000000000000000000000000000007");
assertThat(taskComment.getCreator()).isEqualTo("user_1_1");
}
@ -86,14 +85,12 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentFromNonExistingTaskShouldFail() {
void should_FailToReturnTaskComment_When_TaskCommentIsNotExisting() {
TaskService taskService = taskanaEngine.getTaskService();
ThrowingCallable lambda =
() ->
taskService.getTaskComment(
"Invalid Task Id", "Definately Non Existing Task Comment Id");
() -> taskService.getTaskComment("Definately Non Existing Task Comment Id");
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
}
@ -101,47 +98,12 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetNonExistingTaskCommentShouldFail() {
void should_FailToReturntaskComment_When_TaskIstNotVisible() {
TaskService taskService = taskanaEngine.getTaskService();
ThrowingCallable lambda =
() ->
taskService.getTaskComment(
"TKI:000000000000000000000000000000000002",
"Definately Non Existing Task Comment Id");
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskCommentFromDifferentTaskShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
ThrowingCallable lambda =
() ->
taskService.getTaskComment(
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000003");
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testGetTaskCommentOfNotVisibleTaskShouldFail() {
TaskService taskService = taskanaEngine.getTaskService();
ThrowingCallable lambda =
() ->
taskService.getTaskComment(
"TKI:000000000000000000000000000000000004",
"TCI:000000000000000000000000000000000012");
() -> taskService.getTaskComment("TCI:000000000000000000000000000000000012");
assertThatThrownBy(lambda).isInstanceOf(NotAuthorizedException.class);
}
}

View File

@ -29,7 +29,7 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testUpdateTaskComment()
void should_UpdateTaskComment_For_TaskComment()
throws TaskCommentNotFoundException, NotAuthorizedException, ConcurrencyException,
TaskNotFoundException, InvalidArgumentException {
@ -42,7 +42,7 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
TaskComment taskComment =
taskService.getTaskComment(
"TKI:000000000000000000000000000000000025", "TCI:000000000000000000000000000000000003");
"TCI:000000000000000000000000000000000003");
taskComment.setTextField("updated textfield");
taskService.updateTaskComment(taskComment);
@ -56,7 +56,7 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_2",
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithNoAuthorizationShouldFail()
void should_FailToUpdateTaskComment_When_UserHasNoAuthorization()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
InvalidArgumentException {
@ -69,7 +69,7 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
TaskComment taskComment =
taskService.getTaskComment(
"TKI:000000000000000000000000000000000000", "TCI:000000000000000000000000000000000001");
"TCI:000000000000000000000000000000000001");
taskComment.setTextField("updated textfield");
assertThatThrownBy(() -> taskService.updateTaskComment(taskComment))
@ -86,7 +86,7 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
userName = "user_1_1",
groupNames = {"group_1"})
@Test
void testUpdateTaskCommentWithConcurrentModificationShouldFail()
void should_FailToUpdateTaskComment_When_TaskCommentWasModifiedConcurrently()
throws TaskCommentNotFoundException, NotAuthorizedException, TaskNotFoundException,
ConcurrencyException, InvalidArgumentException {
@ -99,12 +99,12 @@ public class UpdateTaskCommentAccTest extends AbstractAccTest {
TaskComment taskCommentToUpdate =
taskService.getTaskComment(
"TKI:000000000000000000000000000000000000", "TCI:000000000000000000000000000000000002");
"TCI:000000000000000000000000000000000002");
taskCommentToUpdate.setTextField("updated textfield");
TaskComment concurrentTaskCommentToUpdate =
taskService.getTaskComment(
"TKI:000000000000000000000000000000000000", "TCI:000000000000000000000000000000000002");
"TCI:000000000000000000000000000000000002");
concurrentTaskCommentToUpdate.setTextField("concurrently updated textfield");
taskService.updateTaskComment(taskCommentToUpdate);

View File

@ -25,7 +25,8 @@ public final class Mapping {
public static final String URL_VERSION = PRE + "version";
public static final String URL_TASKS = PRE + "tasks";
public static final String URL_TASKS_ID = URL_TASKS + "/{taskId}";
public static final String URL_TASK_COMMENTS = URL_TASKS_ID + "/comments";
public static final String URL_TASK_GET_POST_COMMENTS = URL_TASKS_ID + "/comments";
public static final String URL_TASK_COMMENTS = URL_TASKS + "/comments";
public static final String URL_TASK_COMMENT = URL_TASK_COMMENTS + "/{taskCommentId}";
public static final String URL_TASKS_ID_CLAIM = URL_TASKS_ID + "/claim";
public static final String URL_TASKS_ID_COMPLETE = URL_TASKS_ID + "/complete";

View File

@ -45,15 +45,14 @@ public class TaskCommentController {
@GetMapping(path = Mapping.URL_TASK_COMMENT)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskCommentResource> getTaskComment(
@PathVariable String taskId, @PathVariable String taskCommentId)
public ResponseEntity<TaskCommentResource> getTaskComment(@PathVariable String taskCommentId)
throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException,
InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Entry to getTaskComment(taskId= {}, taskCommentId= {})", taskId, taskCommentId);
LOGGER.debug("Entry to getTaskComment(taskCommentId= {})", taskCommentId);
}
TaskComment taskComment = taskService.getTaskComment(taskId, taskCommentId);
TaskComment taskComment = taskService.getTaskComment(taskCommentId);
TaskCommentResource taskCommentResource = taskCommentResourceAssembler.toResource(taskComment);
@ -66,7 +65,7 @@ public class TaskCommentController {
return response;
}
@GetMapping(path = Mapping.URL_TASK_COMMENTS)
@GetMapping(path = Mapping.URL_TASK_GET_POST_COMMENTS)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskCommentListResource> getTaskComments(@PathVariable String taskId)
throws NotAuthorizedException, TaskNotFoundException {
@ -90,16 +89,14 @@ public class TaskCommentController {
@DeleteMapping(path = Mapping.URL_TASK_COMMENT)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskCommentResource> deleteTaskComment(
@PathVariable String taskId, @PathVariable String taskCommentId)
public ResponseEntity<TaskCommentResource> deleteTaskComment(@PathVariable String taskCommentId)
throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException,
InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Entry to deleteTaskComment(taskId= {}, taskCommentId= {})", taskId, taskCommentId);
LOGGER.debug("Entry to deleteTaskComment(taskCommentId= {})", taskCommentId);
}
taskService.deleteTaskComment(taskId, taskCommentId);
taskService.deleteTaskComment(taskCommentId);
ResponseEntity<TaskCommentResource> result = ResponseEntity.noContent().build();
@ -113,23 +110,19 @@ public class TaskCommentController {
@PutMapping(path = Mapping.URL_TASK_COMMENT)
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskCommentResource> updateTaskComment(
@PathVariable String taskId,
@PathVariable String taskCommentId,
@RequestBody TaskCommentResource taskCommentResource)
@PathVariable String taskCommentId, @RequestBody TaskCommentResource taskCommentResource)
throws NotAuthorizedException, TaskNotFoundException, TaskCommentNotFoundException,
InvalidArgumentException, ConcurrencyException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
"Entry to updateTaskComment(taskId= {}, taskCommentId= {}, taskCommentResource= {})",
taskId,
"Entry to updateTaskComment(taskCommentId= {}, taskCommentResource= {})",
taskCommentId,
taskCommentResource);
}
ResponseEntity<TaskCommentResource> result;
ResponseEntity<TaskCommentResource> result = null;
if ((taskCommentId.equals(taskCommentResource.getTaskCommentId())
&& (taskId.equals(taskCommentResource.getTaskId())))) {
if ((taskCommentId.equals(taskCommentResource.getTaskCommentId()))) {
TaskComment taskComment = taskCommentResourceAssembler.toModel(taskCommentResource);
@ -138,9 +131,9 @@ public class TaskCommentController {
} else {
throw new InvalidArgumentException(
String.format(
"TaskCommentId ('%s') or TaskId ('%s') are not identical with the ids"
+ " of object in the payload which should be updated",
taskCommentId, taskId));
"TaskCommentId ('%s') is not identical with the id"
+ " of the object in the payload which should be updated",
taskCommentId));
}
if (LOGGER.isDebugEnabled()) {
@ -150,7 +143,7 @@ public class TaskCommentController {
return result;
}
@PostMapping(path = Mapping.URL_TASK_COMMENTS)
@PostMapping(path = Mapping.URL_TASK_GET_POST_COMMENTS)
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<TaskCommentResource> createTaskComment(
@PathVariable String taskId, @RequestBody TaskCommentResource taskCommentResource)
@ -163,24 +156,17 @@ public class TaskCommentController {
taskCommentResource);
}
ResponseEntity<TaskCommentResource> result;
taskCommentResource.setTaskId(taskId);
if (taskId.equals(taskCommentResource.getTaskId())) {
TaskComment taskCommentFromResource =
taskCommentResourceAssembler.toModel(taskCommentResource);
TaskComment taskCommentFromResource = taskCommentResourceAssembler.toModel(taskCommentResource);
TaskComment createdTaskComment = taskService.createTaskComment(taskCommentFromResource);
ResponseEntity<TaskCommentResource> result;
result =
ResponseEntity.status(HttpStatus.CREATED)
.body(taskCommentResourceAssembler.toResource(createdTaskComment));
} else {
throw new InvalidArgumentException(
String.format(
"TaskId ('%s') is not identical with the taskId of the"
+ "object in the payload which should be updated.",
taskCommentResource.getTaskId()));
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Exit from createTaskComment(), returning {}", result);
}

View File

@ -43,7 +43,7 @@ public class TaskCommentResourceAssembler
taskCommentResource.add(
linkTo(
methodOn(TaskCommentController.class)
.getTaskComment(taskComment.getTaskId(), taskComment.getId()))
.getTaskComment(taskComment.getId()))
.withSelfRel());
} catch (TaskCommentNotFoundException
| TaskNotFoundException

View File

@ -92,7 +92,8 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
Mapping.URL_TASK_GET_POST_COMMENTS,
"TKI:000000000000000000000000000000000000"))
.accept(MediaTypes.HAL_JSON)
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
.andExpect(MockMvcResultMatchers.status().isOk())
@ -108,9 +109,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
.perform(
RestDocumentationRequestBuilders.get(
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000"))
Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"))
.accept(MediaTypes.HAL_JSON)
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
.andExpect(MockMvcResultMatchers.status().isOk())
@ -123,10 +122,8 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
void updateTaskCommentDocTest() throws Exception {
URL url =
new URL(
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000"));
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"));
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
@ -148,9 +145,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
.perform(
RestDocumentationRequestBuilders.put(
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000"))
Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"))
.header("Authorization", "Basic YWRtaW46YWRtaW4=")
.contentType(MediaTypes.HAL_JSON)
.content(modifiedTaskComment))
@ -174,7 +169,8 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
.perform(
RestDocumentationRequestBuilders.post(
restHelper.toUrl(
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
Mapping.URL_TASK_GET_POST_COMMENTS,
"TKI:000000000000000000000000000000000000"))
.contentType(MediaTypes.HAL_JSON)
.content(createTaskCommentContent)
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
@ -193,10 +189,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
this.mockMvc
.perform(
RestDocumentationRequestBuilders.delete(
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
newId))
restHelper.toUrl(Mapping.URL_TASK_COMMENT, newId))
.header("Authorization", "Basic YWRtaW46YWRtaW4=")) // admin
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(MockMvcRestDocumentation.document("DeleteTaskCommentDocTest"));

View File

@ -42,13 +42,10 @@ class TaskCommentControllerIntTest {
}
@Test
void testGetNonExistentCommentShouldFail() {
void should_FailToReturnTaskComment_When_TaskCommentIsNotExisting() {
String urlToNonExistingTaskComment =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"Non existing task comment Id");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "Non existing task comment Id");
ThrowingCallable httpCall =
() -> {
@ -63,27 +60,9 @@ class TaskCommentControllerIntTest {
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
void testGetCommentsForNonExistingTaskShouldFail() {
String urlToNonExistingTask = restHelper.toUrl(Mapping.URL_TASK_COMMENTS, "nonExistingTaskId");
ThrowingCallable httpCall =
() -> {
template.exchange(
urlToNonExistingTask,
HttpMethod.GET,
new HttpEntity<String>(restHelper.getHeadersAdmin()),
ParameterizedTypeReference.forType(TaskCommentListResource.class));
};
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Disabled("Disabled until Authorization check is up!")
@Test
void testGetTaskCommentsOfNotVisibleTaskShouldFail() {
void should_FailToReturnTaskComments_When_TaskIstNotVisible() {
String urlToNotVisibleTask =
restHelper.toUrl(Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000004");
@ -103,20 +82,17 @@ class TaskCommentControllerIntTest {
@Disabled("Disabled until Authorization check is up!")
@Test
void testGetTaskCommentOfNotVisibleTaskShouldFail() {
void should_FailToReturnTaskComment_When_TaskIstNotVisible() {
String urlToNotVisibleTask =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000004",
"TCI:000000000000000000000000000000000013");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000012");
ThrowingCallable httpCall =
() -> {
template.exchange(
urlToNotVisibleTask,
HttpMethod.GET,
new HttpEntity<String>(restHelper.getHeadersUser_1_1()),
new HttpEntity<String>(restHelper.getHeadersUser_1_2()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
};
assertThatThrownBy(httpCall)
@ -126,17 +102,17 @@ class TaskCommentControllerIntTest {
@Disabled("Disabled until Authorization check is up!")
@Test
void testCreateTaskCommentForNotVisibleTaskShouldFail() {
void should_FailToCreateTaskComment_When_TaskIsNotVisible() {
TaskCommentResource taskCommentResourceToCreate = new TaskCommentResource();
taskCommentResourceToCreate.setTaskId("TKI:000000000000000000000000000000000004");
taskCommentResourceToCreate.setTaskId("TKI:000000000000000000000000000000000000");
taskCommentResourceToCreate.setTextField("newly created task comment");
ThrowingCallable httpCall =
() -> {
template.exchange(
restHelper.toUrl(
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000004"),
Mapping.URL_TASK_GET_POST_COMMENTS, "TKI:000000000000000000000000000000000000"),
HttpMethod.POST,
new HttpEntity<>(taskCommentResourceToCreate, restHelper.getHeadersUser_1_1()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
@ -147,7 +123,7 @@ class TaskCommentControllerIntTest {
}
@Test
void testCreateTaskCommentForNotExistingTaskShouldFail() {
void should_FailToCreateTaskComment_When_TaskIdIsNonExisting() {
TaskCommentResource taskCommentResourceToCreate = new TaskCommentResource();
taskCommentResourceToCreate.setTaskId("DefinatelyNotExistingId");
@ -156,7 +132,7 @@ class TaskCommentControllerIntTest {
ThrowingCallable httpCall =
() -> {
template.exchange(
restHelper.toUrl(Mapping.URL_TASK_COMMENTS, "DefinatelyNotExistingId"),
restHelper.toUrl(Mapping.URL_TASK_GET_POST_COMMENTS, "DefinatelyNotExistingId"),
HttpMethod.POST,
new HttpEntity<>(taskCommentResourceToCreate, restHelper.getHeadersAdmin()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
@ -164,38 +140,17 @@ class TaskCommentControllerIntTest {
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
void testCreateTaskCommentWithDifferentTaskIdInResourceShouldFail() {
TaskCommentResource taskCommentResourceToCreate = new TaskCommentResource();
taskCommentResourceToCreate.setTaskId("TKI:000000000000000000000000000000000000");
taskCommentResourceToCreate.setTextField("newly created task comment");
ThrowingCallable httpCall =
() -> {
template.exchange(
restHelper.toUrl(Mapping.URL_TASK_COMMENTS, "DifferentTaskId"),
HttpMethod.POST,
new HttpEntity<>(taskCommentResourceToCreate, restHelper.getHeadersAdmin()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
};
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
void testUpdateTaskCommentWithConcurrentModificationShouldFail() {
void should_FailToUpdateTaskComment_When_TaskCommentWasModifiedConcurrently() {
final ObjectMapper mapper = new ObjectMapper();
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000");
ResponseEntity<TaskCommentResource> getTaskCommentResponse =
template.exchange(
@ -227,15 +182,12 @@ class TaskCommentControllerIntTest {
@Disabled("Disabled until Authorization check is up!")
@Test
void testUpdateTaskCommentWithNoAuthorizationShouldFail() {
void should_FailToUpdateTaskComment_When_UserHasNoAuthorization() {
final ObjectMapper mapper = new ObjectMapper();
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000");
ResponseEntity<TaskCommentResource> getTaskCommentResponse =
template.exchange(
@ -266,7 +218,7 @@ class TaskCommentControllerIntTest {
}
@Test
void testUpdateTaskCommentOfNotExistingTaskShouldFail() {
void should_FailToUpdateTaskComment_When_TaskIsNotExisting() {
final ObjectMapper mapper = new ObjectMapper();
TaskCommentResource taskCommentResourceToUpdate = new TaskCommentResource();
@ -275,10 +227,7 @@ class TaskCommentControllerIntTest {
taskCommentResourceToUpdate.setTextField("updated text");
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000009999",
"TCI:000000000000000000000000000000000000");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000");
ThrowingCallable httpCall =
() -> {
@ -296,15 +245,12 @@ class TaskCommentControllerIntTest {
}
@Test
void testUpdateTaskCommentWithDifferentIdsInResourceShouldFail() {
void should_FailToUpdateTaskComment_When_TaskCommentIdInResourceDoesNotMatchPathVariable() {
final ObjectMapper mapper = new ObjectMapper();
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000000",
"TCI:000000000000000000000000000000000000");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000");
ResponseEntity<TaskCommentResource> getTaskCommentResponse =
template.exchange(
@ -318,7 +264,7 @@ class TaskCommentControllerIntTest {
TaskCommentResource taskCommentResourceToUpdate = getTaskCommentResponse.getBody();
taskCommentResourceToUpdate.setTextField("updated text");
taskCommentResourceToUpdate.setTaskId("DifferentTaskid");
taskCommentResourceToUpdate.setTaskCommentId("DifferentTaskCommentId");
ThrowingCallable httpCall =
() -> {
@ -333,28 +279,11 @@ class TaskCommentControllerIntTest {
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.BAD_REQUEST);
taskCommentResourceToUpdate.setTaskId("TKI:000000000000000000000000000000000000");
taskCommentResourceToUpdate.setTaskCommentId("DifferentTaskCommentId");
ThrowingCallable httpCall2 =
() -> {
template.exchange(
url,
HttpMethod.PUT,
new HttpEntity<>(
mapper.writeValueAsString(taskCommentResourceToUpdate),
restHelper.getHeadersUser_1_1()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
};
assertThatThrownBy(httpCall2)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.BAD_REQUEST);
}
@Disabled("Disabled until Authorization check is up!")
@Test
void testDeleteTaskCommentWithDifferentUserThanCreatorShouldFail() {
void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() {
ResponseEntity<TaskCommentListResource> getTaskCommentsBeforeDeleteionResponse =
template.exchange(
@ -365,10 +294,7 @@ class TaskCommentControllerIntTest {
assertThat(getTaskCommentsBeforeDeleteionResponse.getBody().getContent()).hasSize(2);
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000001",
"TCI:000000000000000000000000000000000004");
restHelper.toUrl(Mapping.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000004");
ThrowingCallable httpCall =
() -> {
@ -384,35 +310,9 @@ class TaskCommentControllerIntTest {
}
@Test
void testDeleteNonExistingTaskCommentShouldFail() {
void should_FailToDeleteTaskComment_When_TaskCommentIsNotExisting() {
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"TKI:000000000000000000000000000000000001",
"NotExistingTaskComment");
ThrowingCallable httpCall =
() -> {
template.exchange(
url,
HttpMethod.DELETE,
new HttpEntity<String>(restHelper.getHeadersAdmin()),
ParameterizedTypeReference.forType(TaskCommentResource.class));
};
assertThatThrownBy(httpCall)
.extracting(ex -> ((HttpClientErrorException) ex).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
void testDeleteTaskCommentOfNotExistingTaskShouldFail() {
String url =
restHelper.toUrl(
Mapping.URL_TASK_COMMENT,
"NotExistingTaskId",
"TCI:000000000000000000000000000000000004");
String url = restHelper.toUrl(Mapping.URL_TASK_COMMENT, "NotExistingTaskComment");
ThrowingCallable httpCall =
() -> {