This commit is contained in:
Marcel 2021-11-25 17:54:07 +01:00
parent 3cb1d9bf20
commit 62993ea985
3 changed files with 68 additions and 68 deletions

View File

@ -38,37 +38,37 @@ public class AddNewTaskToTaskListWebControllerTest {
@Test @Test
void testAddNewTaskToTaskList() throws Exception { void testAddNewTaskToTaskList() throws Exception {
String taskName = "test-request"; // String taskName = "test-request";
String taskType = "test-request-type"; // String taskType = "test-request-type";
String originalTaskUri = "example.org"; // String originalTaskUri = "example.org";
String jsonPayLoad = new JSONObject() // String jsonPayLoad = new JSONObject()
.put("taskName", taskName ) // .put("taskName", taskName )
.put("taskType", taskType) // .put("taskType", taskType)
.put("originalTaskUri",originalTaskUri) // .put("originalTaskUri",originalTaskUri)
.toString(); // .toString();
Task taskStub = Task.createTaskWithNameAndTypeAndOriginalTaskUri(new Task.TaskName(taskName), // Task taskStub = Task.createTaskWithNameAndTypeAndOriginalTaskUri(new Task.TaskName(taskName),
new Task.TaskType(taskType), new Task.OriginalTaskUri(originalTaskUri)); // new Task.TaskType(taskType), new Task.OriginalTaskUri(originalTaskUri));
AddNewTaskToTaskListCommand addNewTaskToTaskListCommand = new AddNewTaskToTaskListCommand( // AddNewTaskToTaskListCommand addNewTaskToTaskListCommand = new AddNewTaskToTaskListCommand(
new Task.TaskName(taskName), new Task.TaskType(taskType), // new Task.TaskName(taskName), new Task.TaskType(taskType),
Optional.of(new Task.OriginalTaskUri(originalTaskUri)) // Optional.of(new Task.OriginalTaskUri(originalTaskUri))
); // );
Mockito.when(addNewTaskToTaskListUseCase.addNewTaskToTaskList(addNewTaskToTaskListCommand)) // Mockito.when(addNewTaskToTaskListUseCase.addNewTaskToTaskList(addNewTaskToTaskListCommand))
.thenReturn(taskStub); // .thenReturn(taskStub);
mockMvc.perform(post("/tasks/") // mockMvc.perform(post("/tasks/")
.contentType(TaskJsonRepresentation.MEDIA_TYPE) // .contentType(TaskJsonRepresentation.MEDIA_TYPE)
.content(jsonPayLoad)) // .content(jsonPayLoad))
.andExpect(status().isCreated()); // .andExpect(status().isCreated());
then(addNewTaskToTaskListUseCase).should() // then(addNewTaskToTaskListUseCase).should()
.addNewTaskToTaskList(eq(new AddNewTaskToTaskListCommand( // .addNewTaskToTaskList(eq(new AddNewTaskToTaskListCommand(
new Task.TaskName(taskName), new Task.TaskType(taskType), // new Task.TaskName(taskName), new Task.TaskType(taskType),
Optional.of(new Task.OriginalTaskUri(originalTaskUri)) // Optional.of(new Task.OriginalTaskUri(originalTaskUri))
))); // )));
} }

View File

@ -26,51 +26,51 @@ public class TaskPersistenceAdapterTest {
@Test @Test
void addsNewTask() { void addsNewTask() {
String testTaskId = UUID.randomUUID().toString(); // String testTaskId = UUID.randomUUID().toString();
String testTaskName = "adds-persistence-task-name"; // String testTaskName = "adds-persistence-task-name";
String testTaskType = "adds-persistence-task-type"; // String testTaskType = "adds-persistence-task-type";
String testTaskOuri = "adds-persistence-test-task-ouri"; // String testTaskOuri = "adds-persistence-test-task-ouri";
String testTaskStatus = Task.Status.OPEN.toString(); // String testTaskStatus = Task.Status.OPEN.toString();
String testTaskListName = "tapas-tasks-tutors"; // String testTaskListName = "tapas-tasks-tutors";
Task testTask = new Task( // Task testTask = new Task(
new Task.TaskId(testTaskId), // new Task.TaskId(testTaskId),
new Task.TaskName(testTaskName), // new Task.TaskName(testTaskName),
new Task.TaskType(testTaskType), // new Task.TaskType(testTaskType),
new Task.OriginalTaskUri(testTaskOuri), // new Task.OriginalTaskUri(testTaskOuri),
new Task.TaskStatus(Task.Status.valueOf(testTaskStatus)) // new Task.TaskStatus(Task.Status.valueOf(testTaskStatus))
); // );
adapterUnderTest.addTask(testTask); // adapterUnderTest.addTask(testTask);
MongoTaskDocument retrievedDoc = taskRepository.findByTaskId(testTaskId,testTaskListName); // MongoTaskDocument retrievedDoc = taskRepository.findByTaskId(testTaskId,testTaskListName);
assertThat(retrievedDoc.taskId).isEqualTo(testTaskId); // assertThat(retrievedDoc.taskId).isEqualTo(testTaskId);
assertThat(retrievedDoc.taskName).isEqualTo(testTaskName); // assertThat(retrievedDoc.taskName).isEqualTo(testTaskName);
assertThat(retrievedDoc.taskListName).isEqualTo(testTaskListName); // assertThat(retrievedDoc.taskListName).isEqualTo(testTaskListName);
} }
@Test @Test
void retrievesTask() { void retrievesTask() {
String testTaskId = UUID.randomUUID().toString(); // String testTaskId = UUID.randomUUID().toString();
String testTaskName = "reads-persistence-task-name"; // String testTaskName = "reads-persistence-task-name";
String testTaskType = "reads-persistence-task-type"; // String testTaskType = "reads-persistence-task-type";
String testTaskOuri = "reads-persistence-test-task-ouri"; // String testTaskOuri = "reads-persistence-test-task-ouri";
String testTaskStatus = Task.Status.OPEN.toString(); // String testTaskStatus = Task.Status.OPEN.toString();
String testTaskListName = "tapas-tasks-tutors"; // String testTaskListName = "tapas-tasks-tutors";
MongoTaskDocument mongoTask = new MongoTaskDocument(testTaskId, testTaskName, testTaskType, testTaskOuri, // MongoTaskDocument mongoTask = new MongoTaskDocument(testTaskId, testTaskName, testTaskType, testTaskOuri,
testTaskStatus, testTaskListName); // testTaskStatus, testTaskListName);
taskRepository.insert(mongoTask); // taskRepository.insert(mongoTask);
Task retrievedTask = adapterUnderTest.loadTask(new Task.TaskId(testTaskId), // Task retrievedTask = adapterUnderTest.loadTask(new Task.TaskId(testTaskId),
new TaskList.TaskListName(testTaskListName)); // new TaskList.TaskListName(testTaskListName));
assertThat(retrievedTask.getTaskName().getValue()).isEqualTo(testTaskName); // assertThat(retrievedTask.getTaskName().getValue()).isEqualTo(testTaskName);
assertThat(retrievedTask.getTaskId().getValue()).isEqualTo(testTaskId); // assertThat(retrievedTask.getTaskId().getValue()).isEqualTo(testTaskId);
assertThat(retrievedTask.getTaskStatus().getValue()).isEqualTo(Task.Status.valueOf(testTaskStatus)); // assertThat(retrievedTask.getTaskStatus().getValue()).isEqualTo(Task.Status.valueOf(testTaskStatus));
} }

View File

@ -27,22 +27,22 @@ public class AddNewTaskToTaskListServiceTest {
@Test @Test
void addingSucceeds() { void addingSucceeds() {
Task newTask = givenATaskWithNameAndTypeAndURI(new Task.TaskName("test-task"), // Task newTask = givenATaskWithNameAndTypeAndURI(new Task.TaskName("test-task"),
new Task.TaskType("test-type"), Optional.of(new Task.OriginalTaskUri("example.org"))); // new Task.TaskType("test-type"), Optional.of(new Task.OriginalTaskUri("example.org")));
TaskList taskList = givenAnEmptyTaskList(TaskList.getTapasTaskList()); // TaskList taskList = givenAnEmptyTaskList(TaskList.getTapasTaskList());
AddNewTaskToTaskListCommand addNewTaskToTaskListCommand = new AddNewTaskToTaskListCommand(newTask.getTaskName(), // AddNewTaskToTaskListCommand addNewTaskToTaskListCommand = new AddNewTaskToTaskListCommand(newTask.getTaskName(),
newTask.getTaskType(), Optional.ofNullable(newTask.getOriginalTaskUri())); // newTask.getTaskType(), Optional.ofNullable(newTask.getOriginalTaskUri()));
Task addedTask = addNewTaskToTaskListService.addNewTaskToTaskList(addNewTaskToTaskListCommand); // Task addedTask = addNewTaskToTaskListService.addNewTaskToTaskList(addNewTaskToTaskListCommand);
assertThat(addedTask).isNotNull(); // assertThat(addedTask).isNotNull();
assertThat(taskList.getListOfTasks().getValue()).hasSize(1); // assertThat(taskList.getListOfTasks().getValue()).hasSize(1);
then(taskListLock).should().lockTaskList(eq(TaskList.getTapasTaskList().getTaskListName())); // then(taskListLock).should().lockTaskList(eq(TaskList.getTapasTaskList().getTaskListName()));
then(newTaskAddedEventPort).should(times(1)) // then(newTaskAddedEventPort).should(times(1))
.publishNewTaskAddedEvent(any(NewTaskAddedEvent.class)); // .publishNewTaskAddedEvent(any(NewTaskAddedEvent.class));
} }