Testing executor pool #92

Merged
rahimiankeanu merged 7 commits from testing-executorPool into dev 2021-11-28 16:50:43 +00:00
3 changed files with 23 additions and 16 deletions
Showing only changes of commit c0412f6eba - Show all commits

View File

@ -39,11 +39,11 @@ 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);
@ -63,7 +63,7 @@ public class AddNewExecutorToExecutorPoolSystemTest {
HttpEntity<String> 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);
}

View File

@ -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;
@ -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());

View File

@ -31,23 +31,26 @@ 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<ExecutorClass> retrievedExecutor = executorPool.getExecutorByUri(fakeUri);
var retrievedExecutor = executorPool.getAllExecutorsByType(fakeType);
assertThat(retrievedExecutor.isPresent()).isFalse();
assertThat(retrievedExecutor.size()).isEqualTo(0);
}