Code clean up and test fixes

This commit is contained in:
reynisson
2021-12-23 14:14:32 +00:00
parent 4bbe71729c
commit edc2279434
43 changed files with 216 additions and 261 deletions

View File

@@ -9,7 +9,7 @@ import java.util.Set;
public class SelfValidating<T> {
private Validator validator;
private final Validator validator;
public SelfValidating() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

View File

@@ -8,10 +8,10 @@ import org.springframework.stereotype.Repository;
@Repository
public interface ExecutorRepository extends MongoRepository<MongoExecutorDocument, String> {
public MongoExecutorDocument findByExecutorUri(String executorUri, String executorTaskType);
MongoExecutorDocument findByExecutorUri(String executorUri, String executorTaskType);
public List<MongoExecutorDocument> findByExecutorTaskType(String executorTaskType);
List<MongoExecutorDocument> findByExecutorTaskType(String executorTaskType);
public void deleteByExecutorUri(String executorUri);
void deleteByExecutorUri(String executorUri);
}

View File

@@ -4,7 +4,7 @@ import lombok.Getter;
public class ExecutorAddedEvent {
@Getter
private ExecutorClass executorClass;
private final ExecutorClass executorClass;
public ExecutorAddedEvent(ExecutorClass executorClass) { this.executorClass = executorClass; }
}

View File

@@ -4,7 +4,7 @@ import lombok.Getter;
public class ExecutorRemovedEvent {
@Getter
private ExecutorClass executorClass;
private final ExecutorClass executorClass;
public ExecutorRemovedEvent(ExecutorClass executorClass) { this.executorClass = executorClass; }
}

View File

@@ -1,4 +1,4 @@
package ch.unisg.executorpool;
package ch.unisg.executorpool.executorpool;
import org.json.JSONException;
import org.json.JSONObject;
@@ -32,9 +32,9 @@ public class AddNewExecutorToExecutorPoolSystemTest {
ExecutorTaskType executorTaskType = new ExecutorTaskType("system-integration-test-type");
ExecutorUri executorUri = new ExecutorUri(java.net.URI.create("example.org"));
ResponseEntity<String> response = whenAddNewExecutorToEmptyPool(executorTaskType, executorUri);
ResponseEntity response = whenAddNewExecutorToEmptyPool(executorTaskType, executorUri);
JSONObject responseJson = new JSONObject(response.getBody().toString());
var responseJson = new JSONObject(response.getBody().toString());
String respExecutorUri = responseJson.getString("executorUri");
String respExecutorTaskType = responseJson.getString("executorTaskType");
@@ -59,7 +59,7 @@ public class AddNewExecutorToExecutorPoolSystemTest {
HttpEntity<String> request = new HttpEntity<>(jsonPayLoad,headers);
return restTemplate.exchange("/executor-pool/AddExecutor", HttpMethod.POST, request, Object.class);
return restTemplate.exchange("/executor-pool/executors", HttpMethod.POST, request, Object.class);
}

View File

@@ -1,4 +1,4 @@
package ch.unisg.executorpool;
package ch.unisg.executorpool.executorpool.adapter.in.web;
import ch.unisg.executorpool.application.port.out.LoadExecutorPort;
import org.junit.jupiter.api.Test;
@@ -56,7 +56,7 @@ public class AddNewExecutorToExecutorPoolWebControllerTest {
.addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand))
.thenReturn(executorStub);
mockMvc.perform(post("/executor-pool/AddExecutor")
mockMvc.perform(post("/executor-pool/executors")
.contentType(ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE)
.content(jsonPayLoad))
.andExpect(status().isCreated());

View File

@@ -1,4 +1,4 @@
package ch.unisg.executorpool;
package ch.unisg.executorpool.executorpool.application.service;
import static org.mockito.Mockito.times;
@@ -23,12 +23,12 @@ public class AddNewExecutorToExecutorPoolServiceTest {
private final AddExecutorPort addExecutorPort = Mockito.mock(AddExecutorPort.class);
private final ExecutorAddedEventPort newExecutorAddedEventPort = Mockito.mock(ExecutorAddedEventPort.class);
private final AddNewExecutorToExecutorPoolService addNewExecutorToExecutorPoolService = new AddNewExecutorToExecutorPoolService(
newExecutorAddedEventPort, addExecutorPort);
newExecutorAddedEventPort, addExecutorPort);
@Test
void addingSucceeds() {
ExecutorClass newExecutor = givenAnExecutorWithTypeAndUri(new ExecutorClass.ExecutorTaskType("test-type"),
ExecutorClass newExecutor = givenAnExecutorWithTypeAndUri(new ExecutorClass.ExecutorTaskType("test-type"),
new ExecutorClass.ExecutorUri(URI.create("example.org")));
ExecutorPool executorPool = givenAnEmptyExecutorPool(ExecutorPool.getExecutorPool());
@@ -49,9 +49,9 @@ public class AddNewExecutorToExecutorPoolServiceTest {
private ExecutorPool givenAnEmptyExecutorPool(ExecutorPool executorPool) {
executorPool.getListOfExecutors().getValue().clear();
return executorPool;
}
}
private ExecutorClass givenAnExecutorWithTypeAndUri(ExecutorClass.ExecutorTaskType executorTaskType,
private ExecutorClass givenAnExecutorWithTypeAndUri(ExecutorClass.ExecutorTaskType executorTaskType,
ExecutorUri executorUri) {
ExecutorClass executor = Mockito.mock(ExecutorClass.class);
@@ -61,5 +61,5 @@ public class AddNewExecutorToExecutorPoolServiceTest {
}
}

View File

@@ -1,4 +1,4 @@
package ch.unisg.executorpool;
package ch.unisg.executorpool.executorpool.domain;
import java.net.URI;
@@ -13,8 +13,6 @@ import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
public class ExecutorPoolTest {
private static final URI URI = null;
@Test
void addNewExecutorToExecutorPoolSuccess() {
ExecutorPool executorPool = ExecutorPool.getExecutorPool();