Fixed executor-pool tests that were failing
This commit is contained in:
parent
3c8171af8e
commit
c0412f6eba
|
@ -23,7 +23,7 @@ import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri;
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class AddNewExecutorToExecutorPoolSystemTest {
|
public class AddNewExecutorToExecutorPoolSystemTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate restTemplate;
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
|
@ -39,17 +39,17 @@ public class AddNewExecutorToExecutorPoolSystemTest {
|
||||||
ResponseEntity response = whenAddNewExecutorToEmptyPool(executorTaskType, executorUri);
|
ResponseEntity response = whenAddNewExecutorToEmptyPool(executorTaskType, executorUri);
|
||||||
|
|
||||||
JSONObject responseJson = new JSONObject(response.getBody().toString());
|
JSONObject responseJson = new JSONObject(response.getBody().toString());
|
||||||
String respExecutorId = responseJson.getString("executorId");
|
String respExecutorUri = responseJson.getString("executorUri");
|
||||||
String respExecutorTaskType = responseJson.getString("executorTaskType");
|
String respExecutorTaskType = responseJson.getString("executorTaskType");
|
||||||
|
|
||||||
then(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
|
then(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
|
||||||
then(respExecutorId).isNotEmpty();
|
then(respExecutorUri).isEqualTo(executorUri.getValue().toString());
|
||||||
then(respExecutorTaskType).isEqualTo(executorTaskType.getValue());
|
then(respExecutorTaskType).isEqualTo(executorTaskType.getValue());
|
||||||
then(ExecutorPool.getExecutorPool().getListOfExecutors().getValue()).hasSize(1);
|
then(ExecutorPool.getExecutorPool().getListOfExecutors().getValue()).hasSize(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseEntity whenAddNewExecutorToEmptyPool(ExecutorTaskType executorTaskType,
|
private ResponseEntity whenAddNewExecutorToEmptyPool(ExecutorTaskType executorTaskType,
|
||||||
ExecutorUri executorUri) throws JSONException {
|
ExecutorUri executorUri) throws JSONException {
|
||||||
|
|
||||||
ExecutorPool.getExecutorPool().getListOfExecutors().getValue().clear();
|
ExecutorPool.getExecutorPool().getListOfExecutors().getValue().clear();
|
||||||
|
@ -63,8 +63,8 @@ public class AddNewExecutorToExecutorPoolSystemTest {
|
||||||
|
|
||||||
HttpEntity<String> request = new HttpEntity<>(jsonPayLoad,headers);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ch.unisg.executorpool;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import ch.unisg.executorpool.application.port.out.LoadExecutorPort;
|
||||||
import org.bson.json.JsonObject;
|
import org.bson.json.JsonObject;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
@ -27,7 +28,7 @@ import org.json.JSONObject;
|
||||||
|
|
||||||
@WebMvcTest(controllers = AddNewExecutorToExecutorPoolWebController.class)
|
@WebMvcTest(controllers = AddNewExecutorToExecutorPoolWebController.class)
|
||||||
public class AddNewExecutorToExecutorPoolWebControllerTest {
|
public class AddNewExecutorToExecutorPoolWebControllerTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@ -37,6 +38,9 @@ public class AddNewExecutorToExecutorPoolWebControllerTest {
|
||||||
@MockBean
|
@MockBean
|
||||||
ExecutorRepository executorRepository;
|
ExecutorRepository executorRepository;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
LoadExecutorPort loadExecutorPort;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddNewExecutorToExecutorPool() throws Exception {
|
void testAddNewExecutorToExecutorPool() throws Exception {
|
||||||
|
|
||||||
|
@ -55,7 +59,7 @@ public class AddNewExecutorToExecutorPoolWebControllerTest {
|
||||||
.addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand))
|
.addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand))
|
||||||
.thenReturn(executorStub);
|
.thenReturn(executorStub);
|
||||||
|
|
||||||
mockMvc.perform(post("/executorpool/")
|
mockMvc.perform(post("/executor-pool/AddExecutor")
|
||||||
.contentType(ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE)
|
.contentType(ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE)
|
||||||
.content(jsonPayLoad))
|
.content(jsonPayLoad))
|
||||||
.andExpect(status().isCreated());
|
.andExpect(status().isCreated());
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ExecutorPoolTest {
|
||||||
void addNewExecutorToExecutorPoolSuccess() {
|
void addNewExecutorToExecutorPoolSuccess() {
|
||||||
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
|
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
|
||||||
executorPool.getListOfExecutors().getValue().clear();
|
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"));
|
new ExecutorTaskType("test-type"));
|
||||||
|
|
||||||
assertThat(newExecutor.getExecutorTaskType().getValue()).isEqualTo("test-type");
|
assertThat(newExecutor.getExecutorTaskType().getValue()).isEqualTo("test-type");
|
||||||
|
@ -31,26 +31,29 @@ public class ExecutorPoolTest {
|
||||||
@Test
|
@Test
|
||||||
void retrieveExecutorSuccess() {
|
void retrieveExecutorSuccess() {
|
||||||
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
|
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 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
|
@Test
|
||||||
void retrieveExecutorFailure() {
|
void retrieveExecutorFailure() {
|
||||||
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
|
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
|
||||||
|
executorPool.getListOfExecutors().getValue().clear();
|
||||||
executorPool.addNewExecutor(new ExecutorUri(java.net.URI.create("example.com")) , new ExecutorTaskType("test-type"));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user