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",
|
userName = "user_1_1",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test
|
@Test
|
||||||
void testGetNonExistingTaskCommentShouldFail() {
|
void testGetNonExistingTaskCommentFromNonExistingTaskShouldFail() {
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
|
||||||
|
|
@ -97,6 +97,38 @@ public class GetTaskCommentAccTest extends AbstractAccTest {
|
||||||
assertThatThrownBy(lambda).isInstanceOf(TaskCommentNotFoundException.class);
|
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(
|
@WithAccessId(
|
||||||
userName = "user_1_1",
|
userName = "user_1_1",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ public class TaskCommentController {
|
||||||
String.format(
|
String.format(
|
||||||
"TaskCommentId ('%s') or TaskId ('%s') are not identical with the ids"
|
"TaskCommentId ('%s') or TaskId ('%s') are not identical with the ids"
|
||||||
+ " of object in the payload which should be updated",
|
+ " of object in the payload which should be updated",
|
||||||
taskCommentId, taskCommentResource.getTaskId()));
|
taskCommentId, taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
|
@ -177,7 +177,7 @@ public class TaskCommentController {
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
String.format(
|
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.",
|
+ "object in the payload which should be updated.",
|
||||||
taskCommentResource.getTaskId()));
|
taskCommentResource.getTaskId()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.hateoas.MediaTypes;
|
||||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
|
||||||
import org.springframework.restdocs.payload.FieldDescriptor;
|
import org.springframework.restdocs.payload.FieldDescriptor;
|
||||||
|
|
@ -81,8 +82,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
|
|
||||||
allTaskCommentsFieldDescriptors =
|
allTaskCommentsFieldDescriptors =
|
||||||
new FieldDescriptor[] {
|
new FieldDescriptor[] {
|
||||||
subsectionWithPath("task comments")
|
subsectionWithPath("task comments").description("An Array of task comments")
|
||||||
.description("An Array of task comments")
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
RestDocumentationRequestBuilders.get(
|
RestDocumentationRequestBuilders.get(
|
||||||
restHelper.toUrl(
|
restHelper.toUrl(
|
||||||
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
||||||
.accept("application/hal+json")
|
.accept(MediaTypes.HAL_JSON)
|
||||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andDo(
|
.andDo(
|
||||||
|
|
@ -111,7 +111,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
Mapping.URL_TASK_COMMENT,
|
Mapping.URL_TASK_COMMENT,
|
||||||
"TKI:000000000000000000000000000000000000",
|
"TKI:000000000000000000000000000000000000",
|
||||||
"TCI:000000000000000000000000000000000000"))
|
"TCI:000000000000000000000000000000000000"))
|
||||||
.accept("application/hal+json")
|
.accept(MediaTypes.HAL_JSON)
|
||||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andDo(
|
.andDo(
|
||||||
|
|
@ -152,7 +152,7 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
"TKI:000000000000000000000000000000000000",
|
"TKI:000000000000000000000000000000000000",
|
||||||
"TCI:000000000000000000000000000000000000"))
|
"TCI:000000000000000000000000000000000000"))
|
||||||
.header("Authorization", "Basic YWRtaW46YWRtaW4=")
|
.header("Authorization", "Basic YWRtaW46YWRtaW4=")
|
||||||
.contentType("application/json")
|
.contentType(MediaTypes.HAL_JSON)
|
||||||
.content(modifiedTaskComment))
|
.content(modifiedTaskComment))
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||||
.andDo(
|
.andDo(
|
||||||
|
|
@ -165,16 +165,18 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
@Test
|
@Test
|
||||||
void createAndDeleteTaskCommentDocTest() throws Exception {
|
void createAndDeleteTaskCommentDocTest() throws Exception {
|
||||||
|
|
||||||
|
String createTaskCommentContent =
|
||||||
|
"{ \"taskId\" : \"TKI:000000000000000000000000000000000000\",\n"
|
||||||
|
+ " \"textField\" : \"some text in textfield\"} ";
|
||||||
|
|
||||||
MvcResult result =
|
MvcResult result =
|
||||||
this.mockMvc
|
this.mockMvc
|
||||||
.perform(
|
.perform(
|
||||||
RestDocumentationRequestBuilders.post(
|
RestDocumentationRequestBuilders.post(
|
||||||
restHelper.toUrl(
|
restHelper.toUrl(
|
||||||
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
Mapping.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"))
|
||||||
.contentType("application/hal+json")
|
.contentType(MediaTypes.HAL_JSON)
|
||||||
.content(
|
.content(createTaskCommentContent)
|
||||||
"{ \"taskId\" : \"TKI:000000000000000000000000000000000000\",\n"
|
|
||||||
+ " \"textField\" : \"some text in textfield\"} ")
|
|
||||||
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
.header("Authorization", "Basic YWRtaW46YWRtaW4="))
|
||||||
.andExpect(MockMvcResultMatchers.status().isCreated())
|
.andExpect(MockMvcResultMatchers.status().isCreated())
|
||||||
.andDo(
|
.andDo(
|
||||||
|
|
@ -184,8 +186,9 @@ public class TaskCommentControllerRestDocumentation extends BaseRestDocumentatio
|
||||||
responseFields(taskCommentFieldDescriptors)))
|
responseFields(taskCommentFieldDescriptors)))
|
||||||
.andReturn();
|
.andReturn();
|
||||||
|
|
||||||
String content = result.getResponse().getContentAsString();
|
String resultContent = result.getResponse().getContentAsString();
|
||||||
String newId = content.substring(content.indexOf("TCI:"), content.indexOf("TCI:") + 40);
|
String newId =
|
||||||
|
resultContent.substring(resultContent.indexOf("TCI:"), resultContent.indexOf("TCI:") + 40);
|
||||||
|
|
||||||
this.mockMvc
|
this.mockMvc
|
||||||
.perform(
|
.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