diff --git a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java index 05b6099..5c39427 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java @@ -23,7 +23,7 @@ import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class AddNewExecutorToExecutorPoolSystemTest { - + @Autowired private TestRestTemplate restTemplate; @@ -39,17 +39,17 @@ public class AddNewExecutorToExecutorPoolSystemTest { ResponseEntity response = whenAddNewExecutorToEmptyPool(executorTaskType, executorUri); JSONObject responseJson = new JSONObject(response.getBody().toString()); - String respExecutorId = responseJson.getString("executorId"); + String respExecutorUri = responseJson.getString("executorUri"); String respExecutorTaskType = responseJson.getString("executorTaskType"); then(response.getStatusCode()).isEqualTo(HttpStatus.CREATED); - then(respExecutorId).isNotEmpty(); + then(respExecutorUri).isEqualTo(executorUri.getValue().toString()); then(respExecutorTaskType).isEqualTo(executorTaskType.getValue()); then(ExecutorPool.getExecutorPool().getListOfExecutors().getValue()).hasSize(1); - } + } - private ResponseEntity whenAddNewExecutorToEmptyPool(ExecutorTaskType executorTaskType, + private ResponseEntity whenAddNewExecutorToEmptyPool(ExecutorTaskType executorTaskType, ExecutorUri executorUri) throws JSONException { ExecutorPool.getExecutorPool().getListOfExecutors().getValue().clear(); @@ -63,8 +63,8 @@ public class AddNewExecutorToExecutorPoolSystemTest { HttpEntity request = new HttpEntity<>(jsonPayLoad,headers); - return restTemplate.exchange("/executorpool/", HttpMethod.POST, request, Object.class); - + return restTemplate.exchange("/executor-pool/AddExecutor", HttpMethod.POST, request, Object.class); + } } diff --git a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java index 4d6417d..40b7307 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java @@ -2,6 +2,7 @@ package ch.unisg.executorpool; import java.util.Optional; +import ch.unisg.executorpool.application.port.out.LoadExecutorPort; import org.bson.json.JsonObject; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -27,7 +28,7 @@ import org.json.JSONObject; @WebMvcTest(controllers = AddNewExecutorToExecutorPoolWebController.class) public class AddNewExecutorToExecutorPoolWebControllerTest { - + @Autowired private MockMvc mockMvc; @@ -37,6 +38,9 @@ public class AddNewExecutorToExecutorPoolWebControllerTest { @MockBean ExecutorRepository executorRepository; + @MockBean + LoadExecutorPort loadExecutorPort; + @Test void testAddNewExecutorToExecutorPool() throws Exception { @@ -55,7 +59,7 @@ public class AddNewExecutorToExecutorPoolWebControllerTest { .addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand)) .thenReturn(executorStub); - mockMvc.perform(post("/executorpool/") + mockMvc.perform(post("/executor-pool/AddExecutor") .contentType(ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE) .content(jsonPayLoad)) .andExpect(status().isCreated()); diff --git a/executor-pool/src/test/java/ch/unisg/executorpool/ExecutorPoolTest.java b/executor-pool/src/test/java/ch/unisg/executorpool/ExecutorPoolTest.java index d94fd6a..a9df873 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/ExecutorPoolTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/ExecutorPoolTest.java @@ -20,7 +20,7 @@ public class ExecutorPoolTest { void addNewExecutorToExecutorPoolSuccess() { ExecutorPool executorPool = ExecutorPool.getExecutorPool(); executorPool.getListOfExecutors().getValue().clear(); - ExecutorClass newExecutor = executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , + ExecutorClass newExecutor = executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type")); assertThat(newExecutor.getExecutorTaskType().getValue()).isEqualTo("test-type"); @@ -31,26 +31,29 @@ public class ExecutorPoolTest { @Test void retrieveExecutorSuccess() { ExecutorPool executorPool = ExecutorPool.getExecutorPool(); + executorPool.getListOfExecutors().getValue().clear(); ExecutorClass newExecutor = executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type")); - ExecutorClass retrievedExecutor = executorPool.getExecutorByUri(newExecutor.getExecutorUri()).get(); + var retrievedExecutors = executorPool.getAllExecutorsByType(newExecutor.getExecutorTaskType()); - assertThat(retrievedExecutor).isEqualTo(newExecutor); + assertThat(retrievedExecutors.size()).isEqualTo(1); + assertThat(retrievedExecutors.get(0)).isEqualTo(newExecutor); } @Test void retrieveExecutorFailure() { ExecutorPool executorPool = ExecutorPool.getExecutorPool(); + executorPool.getListOfExecutors().getValue().clear(); executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type")); - ExecutorUri fakeUri = new ExecutorUri(java.net.URI.create("fake-Uri")); + var fakeType = new ExecutorTaskType("fake-type"); - Optional retrievedExecutor = executorPool.getExecutorByUri(fakeUri); + var retrievedExecutor = executorPool.getAllExecutorsByType(fakeType); - assertThat(retrievedExecutor.isPresent()).isFalse(); + assertThat(retrievedExecutor.size()).isEqualTo(0); } - + }