Comments from Mustapha Zorgati
This commit is contained in:
parent
c5bb6fb32c
commit
636135bf1a
|
@ -86,7 +86,7 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testGetNonExistingTaskCommentShouldFail() {
|
||||
void testGetNonExistingTaskCommentFromNonExistingTaskShouldFail() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
|
@ -97,6 +97,38 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
|
|||
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testGetNonExistingTaskCommentShouldFail() {
|
||||
|
||||
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"})
|
||||
|
|
|
@ -140,7 +140,7 @@ public class TaskCommentController {
|
|||
String.format(
|
||||
"TaskCommentId ('%s') or TaskId ('%s') are not identical with the ids"
|
||||
+ " of object in the payload which should be updated",
|
||||
taskCommentId, taskCommentResource.getTaskId()));
|
||||
taskCommentId, taskId));
|
||||
}
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
|
@ -177,7 +177,7 @@ public class TaskCommentController {
|
|||
} else {
|
||||
throw new InvalidArgumentException(
|
||||
String.format(
|
||||
"TaskId ('%s') is not identical with the taskId of "
|
||||
"TaskId ('%s') is not identical with the taskId of the"
|
||||
+ "object in the payload which should be updated.",
|
||||
taskCommentResource.getTaskId()));
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.net.URL;
|
|||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
||||
import org.springframework.restdocs.payload.FieldDescriptor;
|
||||
|
@ -81,8 +82,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
|
||||
allTaskCommentsFieldDescriptors =
|
||||
new FieldDescriptor[] {
|
||||
subsectionWithPath("task comments")
|
||||
.description("An Array of task comments")
|
||||
subsectionWithPath("task comments").description("An Array of task comments")
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
RestDocumentationRequestBuilders.get(
|
||||
restHelper.toUrl(
|
||||
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
||||
.accept("application/hal+json")
|
||||
.accept(MediaTypes.HAL_JSON)
|
||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(
|
||||
|
@ -111,7 +111,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
Mapping.URL_TASK_COMMENT,
|
||||
"TKI:000000000000000000000000000000000000",
|
||||
"TCI:000000000000000000000000000000000000"))
|
||||
.accept("application/hal+json")
|
||||
.accept(MediaTypes.HAL_JSON)
|
||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(
|
||||
|
@ -152,7 +152,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
"TKI:000000000000000000000000000000000000",
|
||||
"TCI:000000000000000000000000000000000000"))
|
||||
.header("Authorization", "Basic YWRtaW46YWRtaW4=")
|
||||
.contentType("application/json")
|
||||
.contentType(MediaTypes.HAL_JSON)
|
||||
.content(modifiedTaskComment))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(
|
||||
|
@ -165,16 +165,18 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
@Test
|
||||
void createAndDeleteTaskCommentDocTest() throws Exception {
|
||||
|
||||
String createTaskCommentContent =
|
||||
"{ \"taskId\" : \"TKI:000000000000000000000000000000000000\",\n"
|
||||
+ " \"textField\" : \"some text in textfield\"} ";
|
||||
|
||||
MvcResult result =
|
||||
this.mockMvc
|
||||
.perform(
|
||||
RestDocumentationRequestBuilders.post(
|
||||
restHelper.toUrl(
|
||||
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
||||
.contentType("application/hal+json")
|
||||
.content(
|
||||
"{ \"taskId\" : \"TKI:000000000000000000000000000000000000\",\n"
|
||||
+ " \"textField\" : \"some text in textfield\"} ")
|
||||
.contentType(MediaTypes.HAL_JSON)
|
||||
.content(createTaskCommentContent)
|
||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||
.andExpect(MockMvcResultMatchers.status().isCreated())
|
||||
.andDo(
|
||||
|
@ -184,8 +186,9 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
|||
responseFields(taskCommentFieldDescriptors)))
|
||||
.andReturn();
|
||||
|
||||
String content = result.getResponse().getContentAsString();
|
||||
String newId = content.substring(content.indexOf("TCI:"), content.indexOf("TCI:") + 40);
|
||||
String resultContent = result.getResponse().getContentAsString();
|
||||
String newId =
|
||||
resultContent.substring(resultContent.indexOf("TCI:"), resultContent.indexOf("TCI:") + 40);
|
||||
|
||||
this.mockMvc
|
||||
.perform(
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package pro.taskana.rest.resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import pro.taskana.TaskanaSpringBootTest;
|
||||
import pro.taskana.task.api.TaskService;
|
||||
import pro.taskana.task.api.models.TaskComment;
|
||||
import pro.taskana.task.internal.models.TaskCommentImpl;
|
||||
|
||||
/** Test for {@link TaskCommentResourceAssembler}. */
|
||||
@TaskanaSpringBootTest
|
||||
public class TaskCommentResourceAssemblerTest {
|
||||
|
||||
private final TaskCommentResourceAssembler taskCommentResourceAssembler;
|
||||
private final TaskService taskService;
|
||||
|
||||
@Autowired
|
||||
TaskCommentResourceAssemblerTest(
|
||||
TaskCommentResourceAssembler taskCommentResourceAssembler, TaskService taskService) {
|
||||
this.taskCommentResourceAssembler = taskCommentResourceAssembler;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskCommentModelToResource() {
|
||||
|
||||
TaskCommentImpl taskComment =
|
||||
(TaskCommentImpl) taskService.newTaskComment("TKI:000000000000000000000000000000000000");
|
||||
|
||||
taskComment.setCreator("user_1_1");
|
||||
taskComment.setTextField("this is a task comment");
|
||||
taskComment.setCreated(Instant.parse("2010-01-01T12:00:00Z"));
|
||||
taskComment.setModified(Instant.parse("2011-11-11T11:00:00Z"));
|
||||
|
||||
TaskCommentResource taskCommentResource = taskCommentResourceAssembler.toResource(taskComment);
|
||||
|
||||
testEquality(taskComment, taskCommentResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskCommentResourceToModel() {
|
||||
|
||||
TaskCommentResource taskCommentResource = new TaskCommentResource();
|
||||
taskCommentResource.setTaskId("TKI:000000000000000000000000000000000000");
|
||||
taskCommentResource.setTaskCommentId("TCI:000000000000000000000000000000000000");
|
||||
taskCommentResource.setCreator("user_1_1");
|
||||
taskCommentResource.setCreated("2010-01-01T12:00:00Z");
|
||||
taskCommentResource.setModified("2011-11-11T11:00:00Z");
|
||||
|
||||
TaskComment taskComment = taskCommentResourceAssembler.toModel(taskCommentResource);
|
||||
|
||||
testEquality(taskComment, taskCommentResource);
|
||||
}
|
||||
|
||||
private void testEquality(TaskComment taskComment, TaskCommentResource taskCommentResource) {
|
||||
|
||||
assertThat(taskComment.getTaskId()).isEqualTo(taskCommentResource.getTaskId());
|
||||
assertThat(taskComment.getId()).isEqualTo(taskCommentResource.getTaskCommentId());
|
||||
assertThat(taskComment.getCreator()).isEqualTo(taskCommentResource.getCreator());
|
||||
assertThat(taskComment.getTextField()).isEqualTo(taskCommentResource.getTextField());
|
||||
assertThat(taskComment.getCreated()).isEqualTo(taskCommentResource.getCreated());
|
||||
assertThat(taskComment.getModified()).isEqualTo(taskCommentResource.getModified());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue