fixed some of the tests

This commit is contained in:
julius.lautz 2021-11-26 13:07:10 +01:00 committed by reynisson
parent 1661db5d47
commit 767dcfa82a
6 changed files with 42 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -18,18 +18,23 @@ public class RosterTest {
Roster roster = Roster.getInstance();
Collection<RosterItem> rosterMap = roster.getRosterMap();
rosterMap.clear();
// TODO change test-type to upper case
roster.addTaskToQueue(new Task("test-id", "test-type"));
Task task = roster.assignTaskToExecutor(new ExecutorType("test-type"), new ExecutorURI("Test-URI"));
Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
queues.clear();
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.iterator().next().getTaskID()).isEqualTo("test-id");
assertThat(rosterMap.iterator().next().getTaskType()).isEqualTo("test-type");
// TODO test uri
assertThat(rosterMap.iterator().next().getTaskID()).isEqualTo("TEST-ID");
assertThat(rosterMap.iterator().next().getTaskType()).isEqualTo("TEST-TYPE");
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
@ -37,11 +42,11 @@ public class RosterTest {
Roster roster = Roster.getInstance();
Collection<ArrayList<Task>> queues = roster.getAllTasksFromQueue();
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);
// TODO check that the queue has size 0
assertThat(queues.size()).isEqualTo(1);
}
}

View File

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