Fixed some roster tests

This commit is contained in:
reynisson 2021-11-26 14:48:49 +01:00
parent 2f36e01c57
commit 49977ae8a2
6 changed files with 34 additions and 27 deletions

View File

@ -17,6 +17,7 @@ public class ApplyForTaskController {
this.applyForTaskUseCase = applyForTaskUseCase; this.applyForTaskUseCase = applyForTaskUseCase;
} }
// TODO fix return type
/** /**
* Checks if task is available for the requesting executor. * Checks if task is available for the requesting executor.
* @return a task or null if no task found * @return a task or null if no task found

View File

@ -28,7 +28,7 @@ public class AddNewAssignmentToRosterServiceSystemTest {
String rosterItemId = "TEST-ID"; String rosterItemId = "TEST-ID";
String executorType = "TEST-TYPE"; String executorType = "TEST-TYPE";
String executorURI = "TEST-URI"; String executorURI = "http://localhost:6969";
ResponseEntity response = whenAddNewAssignmentToRoster(rosterItemId, executorType, executorURI); ResponseEntity response = whenAddNewAssignmentToRoster(rosterItemId, executorType, executorURI);

View File

@ -37,12 +37,12 @@ public class ApplyForTaskControllerTest {
void testApplyForTask() throws Exception{ void testApplyForTask() throws Exception{
String executorType = "TEST-TYPE"; String executorType = "TEST-TYPE";
String executorURI = "TEST-URI"; String executorURI = "http://localhost:6969";
String taskId = "TEST-ID"; String taskId = "TEST-ID";
String jsonPayLoad = new JSONObject() String jsonPayLoad = new JSONObject()
.put("executorType", executorType ) .put("executorType", executorType )
.put("executorUri",executorURI) .put("executorURI",executorURI)
.toString(); .toString();
RosterItem rosterItem = new RosterItem(taskId, executorType, RosterItem rosterItem = new RosterItem(taskId, executorType,
@ -60,7 +60,7 @@ public class ApplyForTaskControllerTest {
mockMvc.perform(post("/task/apply/") mockMvc.perform(post("/task/apply/")
.contentType("application/json") .contentType("application/json")
.content(jsonPayLoad)) .content(jsonPayLoad))
.andExpect(status().isCreated()); .andExpect(status().is2xxSuccessful());
//TODO: No idea why this does not work yet //TODO: No idea why this does not work yet
then(applyForTaskUseCase).should() then(applyForTaskUseCase).should()

View File

@ -10,9 +10,11 @@ import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataM
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureDataMongo @AutoConfigureDataMongo
@Import({RosterPersistenceAdapter.class, RosterMapper.class}) @Import({RosterPersistenceAdapter.class, RosterMapper.class})
public class RosterPersistenceAdapterTest { public class RosterPersistenceAdapterTest {
@ -26,7 +28,7 @@ public class RosterPersistenceAdapterTest {
@Test @Test
void addsNewRosterItem(){ void addsNewRosterItem(){
String taskId = "TEST-ID"; String taskId = UUID.randomUUID().toString();
String executorType = "TEST-TYPE"; String executorType = "TEST-TYPE";
String executorURI = "TEST-URI"; String executorURI = "TEST-URI";
@ -35,6 +37,8 @@ public class RosterPersistenceAdapterTest {
executorType, executorType,
new ExecutorURI(executorURI) new ExecutorURI(executorURI)
); );
adapterUnderTest.addRosterItem(testRosterItem); adapterUnderTest.addRosterItem(testRosterItem);
MongoRosterDocument retrievedDoc = rosterRepository.findByTaskId(taskId); MongoRosterDocument retrievedDoc = rosterRepository.findByTaskId(taskId);
@ -48,7 +52,7 @@ public class RosterPersistenceAdapterTest {
@Test @Test
void retrievesRosterItem(){ void retrievesRosterItem(){
String taskId = "TEST-ID"; String taskId = UUID.randomUUID().toString();
String executorType = "TEST-TYPE"; String executorType = "TEST-TYPE";
String executorURI = "TEST-URI"; String executorURI = "TEST-URI";
@ -59,6 +63,6 @@ public class RosterPersistenceAdapterTest {
assertThat(retrievedRosterItem.getTaskID()).isEqualTo(taskId); assertThat(retrievedRosterItem.getTaskID()).isEqualTo(taskId);
assertThat(retrievedRosterItem.getTaskType()).isEqualTo(executorType); assertThat(retrievedRosterItem.getTaskType()).isEqualTo(executorType);
assertThat(retrievedRosterItem.getExecutorURI()).isEqualTo(executorURI); assertThat(retrievedRosterItem.getExecutorURI().getValue().toString()).isEqualTo(executorURI);
} }
} }

View File

@ -1,2 +1,2 @@
spring.data.mongodb.uri=mongodb://127.0.0.1:27017 spring.data.mongodb.uri=mongodb://127.0.0.1:27017
spring.data.mongodb.database=tapas-tasks spring.data.mongodb.database=tapas-roster

View File

@ -26,28 +26,30 @@ 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)),
// ); new Task.InputData("asd"),
// adapterUnderTest.addTask(testTask); new Task.OutputData("")
);
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);
} }