Skip to content

Commit

Permalink
notificationService implementation instead of Mock
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu DEHARBE <[email protected]>
  • Loading branch information
Mathieu-Deharbe committed Jun 18, 2024
1 parent fdf16d4 commit 2e024ea
Showing 1 changed file with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;

Expand All @@ -56,14 +57,15 @@
class ComputationTest implements WithAssertions {
private static final String COMPUTATION_TYPE = "mockComputation";
@Mock
private VariantManager variantManager;
@Mock
private NetworkStoreService networkStoreService;
@Mock
private ReportService reportService;
private final ExecutionService executionService = new ExecutionService();
private final UuidGeneratorService uuidGeneratorService = new UuidGeneratorService();
@Mock
private ExecutionService executionService;
@Mock
private UuidGeneratorService uuidGeneratorService = new UuidGeneratorService();
@Mock
private StreamBridge publisher;
private NotificationService notificationService;
@Mock
private ObjectMapper objectMapper;
Expand Down Expand Up @@ -182,7 +184,7 @@ protected CompletableFuture<MockComputationResult> getCompletableFuture(MockComp
final CompletableFuture<MockComputationResult> completableFuture = new CompletableFuture<>();
switch (runContext.getComputationResWanted()) {
case FAIL:
completableFuture.completeExceptionally(new RuntimeException("Computation failed"));
completableFuture.completeExceptionally(new RuntimeException("Computation failed but with an artificially longer messaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaage"));
break;
case SUCCESS:
return CompletableFuture.supplyAsync(MockComputationResult::new);
Expand All @@ -191,11 +193,7 @@ protected CompletableFuture<MockComputationResult> getCompletableFuture(MockComp
}
}

@Mock
private VariantManager variantManager;
@Mock
private MockComputationWorkerService workerService;
@Mock
private MockComputationService computationService;
private MockComputationResultContext resultContext;
final UUID networkUuid = UUID.fromString("11111111-1111-1111-1111-111111111111");
Expand All @@ -211,6 +209,7 @@ protected CompletableFuture<MockComputationResult> getCompletableFuture(MockComp
@BeforeEach
void init() {
MockComputationResultService resultService = new MockComputationResultService();
notificationService = new NotificationService(publisher);
workerService = new MockComputationWorkerService(
networkStoreService,
notificationService,
Expand Down Expand Up @@ -251,8 +250,7 @@ void testComputationSuccess() {
workerService.consumeRun().accept(message);

// test the course
verify(notificationService, times(1))
.sendResultMessage(resultUuid, receiver, userId, null);
verify(notificationService.getPublisher(), times(1)).send(eq("publishResult-out-0"), isA(Message.class));
}

@Test
Expand All @@ -265,8 +263,7 @@ void testComputationFailed() {
workerService.consumeRun().accept(message);

// test the course
verify(notificationService, times(1))
.publishFail(resultUuid, receiver, "java.lang.RuntimeException: Computation failed", userId, COMPUTATION_TYPE, null);
verify(notificationService.getPublisher(), times(1)).send(eq("publishFailed-out-0"), isA(Message.class));
}

@Test
Expand All @@ -278,10 +275,8 @@ void testComputationCancelled() {
computationService.stop(resultUuid, receiver);

// test the course
verify(notificationService, times(1))
.sendCancelMessage(isA(Message.class));
verify(notificationService.getPublisher(), times(1)).send(eq("publishCancel-out-0"), isA(Message.class));

// TODO : how to get the message from the previous call instead of creating this one ?
Message<String> cancelMessage = MessageBuilder.withPayload("")
.setHeader(HEADER_RESULT_UUID, resultUuid.toString())
.setHeader(HEADER_RECEIVER, receiver)
Expand Down

0 comments on commit 2e024ea

Please sign in to comment.