diff --git a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java index 5da6fe7..021b58b 100644 --- a/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java +++ b/executor-pool/src/main/java/ch/unisg/executorpool/domain/ExecutorClass.java @@ -18,7 +18,7 @@ public class ExecutorClass { this.executorTaskType = executorTaskType; } - protected static ExecutorClass createExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ + public static ExecutorClass createExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){ System.out.println("New Executor: " + executorUri.value.toString() + " " + executorTaskType.getValue()); return new ExecutorClass(executorUri, executorTaskType); } diff --git a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolServiceTest.java b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolServiceTest.java index 27f447b..3f6f70e 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolServiceTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolServiceTest.java @@ -3,19 +3,20 @@ package ch.unisg.executorpool; import static org.mockito.Mockito.times; import java.net.URI; -import java.util.Optional; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import static org.mockito.BDDMockito.*; import static org.assertj.core.api.Assertions.*; -import static org.mockito.BDDMockito.then; import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolCommand; import ch.unisg.executorpool.application.port.out.AddExecutorPort; import ch.unisg.executorpool.application.port.out.ExecutorAddedEventPort; import ch.unisg.executorpool.application.service.AddNewExecutorToExecutorPoolService; +import ch.unisg.executorpool.domain.ExecutorAddedEvent; import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.executorpool.domain.ExecutorPool; +import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; public class AddNewExecutorToExecutorPoolServiceTest { @@ -28,19 +29,19 @@ public class AddNewExecutorToExecutorPoolServiceTest { void addingSucceeds() { ExecutorClass newExecutor = givenAnExecutorWithTypeAndUri(new ExecutorClass.ExecutorTaskType("test-type"), - Optional.of(new ExecutorClass.ExecutorUri(URI.create("example.org")))); + new ExecutorClass.ExecutorUri(URI.create("example.org"))); ExecutorPool executorPool = givenAnEmptyExecutorPool(ExecutorPool.getExecutorPool()); - AddNewExecutorToExecutorPoolCommand addNewExecutorToExecutorPoolCommand = new AddNewExecutorToExecutorPoolCommand(newExecutor.getExecutorTaskType(), - Optional.ofNullable(newExecutor.getExecutorUri())); + AddNewExecutorToExecutorPoolCommand addNewExecutorToExecutorPoolCommand = new AddNewExecutorToExecutorPoolCommand( + newExecutor.getExecutorUri(), newExecutor.getExecutorTaskType()); ExecutorClass addedExecutor = addNewExecutorToExecutorPoolService.addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand); assertThat(addedExecutor).isNotNull(); assertThat(executorPool.getListOfExecutors().getValue()).hasSize(1); - then(newExecutorAddedEventPort).should(times(1)).publishNewExecutorAddedEvent(any(NewExecutorAddedEvent.class)); + then(newExecutorAddedEventPort).should(times(1)).publishExecutorAddedEvent(any(ExecutorAddedEvent.class)); } @@ -51,11 +52,11 @@ public class AddNewExecutorToExecutorPoolServiceTest { } private ExecutorClass givenAnExecutorWithTypeAndUri(ExecutorClass.ExecutorTaskType executorTaskType, - Optional executorUri) { + ExecutorUri executorUri) { ExecutorClass executor = Mockito.mock(ExecutorClass.class); - given(ExecutorClass.getExecutorTaskType()).willReturn(executorTaskType); - given(ExecutorClass.getExecutorUri()).willReturn(executorUri); + given(executor.getExecutorTaskType()).willReturn(executorTaskType); + given(executor.getExecutorUri()).willReturn(executorUri); return executor; } 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 1eba971..05b6099 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolSystemTest.java @@ -11,7 +11,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -//import static org.mockito.BDDMockito.then; +import static org.assertj.core.api.BDDAssertions.*; import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; import ch.unisg.executorpool.application.port.out.AddExecutorPort; 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 cc28edb..4d6417d 100644 --- a/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java +++ b/executor-pool/src/test/java/ch/unisg/executorpool/AddNewExecutorToExecutorPoolWebControllerTest.java @@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation; import ch.unisg.executorpool.adapter.in.web.AddNewExecutorToExecutorPoolWebController; @@ -20,7 +22,7 @@ import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolUse import ch.unisg.executorpool.domain.ExecutorClass; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType; import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri; -import net.minidev.json.JSONObject; +import org.json.JSONObject; @WebMvcTest(controllers = AddNewExecutorToExecutorPoolWebController.class) @@ -47,7 +49,7 @@ public class AddNewExecutorToExecutorPoolWebControllerTest { new ExecutorClass.ExecutorTaskType(executorTaskType)); AddNewExecutorToExecutorPoolCommand addNewExecutorToExecutorPoolCommand = new AddNewExecutorToExecutorPoolCommand( - new ExecutorTaskType(executorTaskType), Optional.of(new ExecutorUri(java.net.URI.create(executorUri)))); + new ExecutorUri(java.net.URI.create(executorUri)), new ExecutorTaskType(executorTaskType)); Mockito.when(addNewExecutorToExecutorPoolUseCase .addNewExecutorToExecutorPool(addNewExecutorToExecutorPoolCommand)) @@ -60,7 +62,7 @@ public class AddNewExecutorToExecutorPoolWebControllerTest { then(addNewExecutorToExecutorPoolUseCase).should() .addNewExecutorToExecutorPool(eq(new AddNewExecutorToExecutorPoolCommand( - new ExecutorTaskType(executorTaskType), Optional.of(new ExecutorUri(java.net.URI.create(executorUri)))))); + new ExecutorUri(java.net.URI.create(executorUri)), new ExecutorTaskType(executorTaskType)))); }