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

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

View File

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