ExecutorPoolTest code should be fine.
But half of tests failed
This commit is contained in:
parent
e03fc296ee
commit
3c8171af8e
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<ExecutorClass.ExecutorUri> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))));
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user