Exercise 8 PR #95

Merged
reynisson merged 68 commits from dev into main 2021-11-29 06:46:44 +00:00
5 changed files with 40 additions and 33 deletions
Showing only changes of commit 2f36e01c57 - Show all commits

View File

@ -26,9 +26,9 @@ public class AddNewAssignmentToRosterServiceSystemTest {
@Test @Test
void addNewAssignmentToRosterService() throws JSONException { void addNewAssignmentToRosterService() throws JSONException {
String rosterItemId = "test-id"; String rosterItemId = "TEST-ID";
String executorType = "test-type"; String executorType = "TEST-TYPE";
String executorURI = "test-URI"; String executorURI = "TEST-URI";
ResponseEntity response = whenAddNewAssignmentToRoster(rosterItemId, executorType, executorURI); ResponseEntity response = whenAddNewAssignmentToRoster(rosterItemId, executorType, executorURI);
@ -65,7 +65,7 @@ public class AddNewAssignmentToRosterServiceSystemTest {
HttpEntity<String> request = new HttpEntity<>(jsonPayLoad, headers); HttpEntity<String> request = new HttpEntity<>(jsonPayLoad, headers);
return restTemplate.exchange( return restTemplate.exchange(
"/tasks/apply/", "/task/apply/",
HttpMethod.POST, HttpMethod.POST,
request, request,
Object.class Object.class

View File

@ -36,9 +36,9 @@ public class ApplyForTaskControllerTest {
@Test @Test
void testApplyForTask() throws Exception{ void testApplyForTask() throws Exception{
String executorType = "test-type"; String executorType = "TEST-TYPE";
String executorURI = "test-uri"; String executorURI = "TEST-URI";
String taskId = "test-id"; String taskId = "TEST-ID";
String jsonPayLoad = new JSONObject() String jsonPayLoad = new JSONObject()
.put("executorType", executorType ) .put("executorType", executorType )
@ -56,15 +56,15 @@ public class ApplyForTaskControllerTest {
Mockito.when(applyForTaskUseCase.applyForTask(applyForTaskCommand)) Mockito.when(applyForTaskUseCase.applyForTask(applyForTaskCommand))
.thenReturn(taskStub); .thenReturn(taskStub);
// TODO Add slash at the front
mockMvc.perform(post("tasks/apply/") mockMvc.perform(post("/task/apply/")
.contentType("application/json") .contentType("application/json")
.content(jsonPayLoad)) .content(jsonPayLoad))
.andExpect(status().isCreated()); .andExpect(status().isCreated());
//TODO: No idea why this does not work yet
then(applyForTaskUseCase).should() then(applyForTaskUseCase).should()
.applyForTask(new ApplyForTaskCommand(new ExecutorType(executorType), .applyForTask(new ApplyForTaskCommand(new ExecutorType(executorType), new ExecutorURI(executorURI)));
new ExecutorURI(executorURI)));
} }
} }

View File

@ -21,21 +21,21 @@ public class RosterPersistenceAdapterTest {
private RosterRepository rosterRepository; private RosterRepository rosterRepository;
@Autowired @Autowired
private RosterPersistenceAdapter adapterunderTest; private RosterPersistenceAdapter adapterUnderTest;
@Test @Test
void addsNewRosterItem(){ void addsNewRosterItem(){
String taskId = "test-id"; String taskId = "TEST-ID";
String executorType = "test-type"; String executorType = "TEST-TYPE";
String executorURI = "test-uri"; String executorURI = "TEST-URI";
RosterItem testRosterItem = new RosterItem( RosterItem testRosterItem = new RosterItem(
taskId, taskId,
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,14 +48,14 @@ public class RosterPersistenceAdapterTest {
@Test @Test
void retrievesRosterItem(){ void retrievesRosterItem(){
String taskId = "test-id"; String taskId = "TEST-ID";
String executorType = "test-type"; String executorType = "TEST-TYPE";
String executorURI = "test-uri"; String executorURI = "TEST-URI";
MongoRosterDocument mongoRosterDocument = new MongoRosterDocument(taskId, executorType, executorURI); MongoRosterDocument mongoRosterDocument = new MongoRosterDocument(taskId, executorType, executorURI);
rosterRepository.insert(mongoRosterDocument); rosterRepository.insert(mongoRosterDocument);
RosterItem retrievedRosterItem = adapterunderTest.loadRosterItem(taskId); RosterItem retrievedRosterItem = adapterUnderTest.loadRosterItem(taskId);
assertThat(retrievedRosterItem.getTaskID()).isEqualTo(taskId); assertThat(retrievedRosterItem.getTaskID()).isEqualTo(taskId);
assertThat(retrievedRosterItem.getTaskType()).isEqualTo(executorType); assertThat(retrievedRosterItem.getTaskType()).isEqualTo(executorType);

View File

@ -39,9 +39,11 @@ public class AddNewAssignmentToRosterServiceTest {
@Test @Test
void assigningSucceeds(){ void assigningSucceeds(){
Task newTask = givenATaskWithIdAndType("test-id", "test-type", "test-input"); Task newTask = givenATaskWithIdAndType("TEST-ID", "TEST-TYPE", "TEST-INPUT");
RosterItem newRosterItem = givenARosterItemWithIdAndTypeAndExecutorUri("test-id", "test-type", "test-uri"); RosterItem newRosterItem = givenARosterItemWithIdAndTypeAndExecutorUri("TEST-ID", "TEST-TYPE", "TEST-URI");
// TODO Add task to queue // TODO Add task to queue
Roster roster = Roster.getInstance();
roster.addTaskToQueue(newTask);
ApplyForTaskCommand applyForTaskCommand = new ApplyForTaskCommand(newTask.getTaskType(), newRosterItem.getExecutorURI()); ApplyForTaskCommand applyForTaskCommand = new ApplyForTaskCommand(newTask.getTaskType(), newRosterItem.getExecutorURI());

View File

@ -18,18 +18,23 @@ public class RosterTest {
Roster roster = Roster.getInstance(); Roster roster = Roster.getInstance();
Collection<RosterItem> rosterMap = roster.getRosterMap(); Collection<RosterItem> rosterMap = roster.getRosterMap();
rosterMap.clear(); rosterMap.clear();
// TODO change test-type to upper case Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
roster.addTaskToQueue(new Task("test-id", "test-type")); queues.clear();
Task task = roster.assignTaskToExecutor(new ExecutorType("test-type"), new ExecutorURI("Test-URI")); roster.addTaskToQueue(new Task("TEST-ID", "TEST-TYPE"));
Task task = roster.assignTaskToExecutor(new ExecutorType("TEST-TYPE"), new ExecutorURI("TEST-URI"));
assertThat(rosterMap.size()).isEqualTo(1); assertThat(rosterMap.size()).isEqualTo(1);
assertThat(rosterMap.iterator().next().getTaskID()).isEqualTo("test-id"); assertThat(rosterMap.iterator().next().getTaskID()).isEqualTo("TEST-ID");
assertThat(rosterMap.iterator().next().getTaskType()).isEqualTo("test-type"); assertThat(rosterMap.iterator().next().getTaskType()).isEqualTo("TEST-TYPE");
// TODO test uri assertThat(rosterMap.iterator().next().getExecutorURI().getValue().toString()).isEqualTo("TEST-URI");
// TODO test id and type of Task task assertThat(task.getTaskType().getValue().toString()).isEqualTo("TEST-TYPE");
assertThat(task.getTaskID()).isEqualTo("TEST-ID");
// TODO test that the task was removed from the Queue similar to below boolean empty_queue = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));
// TODO test that the task was removed from the Queue similar to below --> I don't know if it actually gets deleted or not
//assertThat(empty_queue).isEqualTo(true);
//assertThat(queues.size()).isEqualTo(0);
} }
@Test @Test
@ -37,11 +42,11 @@ public class RosterTest {
Roster roster = Roster.getInstance(); Roster roster = Roster.getInstance();
Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue(); Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
queues.clear(); queues.clear();
roster.addTaskToQueue(new Task("test-id", "test-type")); roster.addTaskToQueue(new Task("TEST-ID", "TEST-TYPE"));
boolean test = roster.deleteTask("test-id", new ExecutorType("test-type")); boolean test = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));
assertThat(test).isEqualTo(true); assertThat(test).isEqualTo(true);
// TODO check that the queue has size 0 assertThat(queues.size()).isEqualTo(1);
} }
} }