11/*
2- * Copyright 2022-2023 IEXEC BLOCKCHAIN TECH
2+ * Copyright 2022-2024 IEXEC BLOCKCHAIN TECH
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3232import lombok .SneakyThrows ;
3333import org .junit .jupiter .api .BeforeEach ;
3434import org .junit .jupiter .api .Test ;
35+ import org .junit .jupiter .api .extension .ExtendWith ;
3536import org .mockito .InjectMocks ;
3637import org .mockito .Mock ;
37- import org .mockito .MockitoAnnotations ;
38+ import org .mockito .junit . jupiter . MockitoExtension ;
3839import org .springframework .http .HttpStatus ;
3940import org .springframework .http .ResponseEntity ;
4041import org .web3j .crypto .Credentials ;
4748import static org .junit .jupiter .api .Assertions .*;
4849import static org .mockito .Mockito .*;
4950
51+ @ ExtendWith (MockitoExtension .class )
5052class TaskControllerTests {
5153
5254 private static final String TASK_ID = "0xtask" ;
@@ -74,7 +76,6 @@ class TaskControllerTests {
7476 @ BeforeEach
7577 @ SneakyThrows
7678 void setUp () {
77- MockitoAnnotations .openMocks (this );
7879 EIP712Domain domain = new EIP712Domain ();
7980 challenge = new EIP712Challenge (domain , Challenge .builder ().challenge ("challenge" ).build ());
8081 badChallenge = new EIP712Challenge (domain , Challenge .builder ().challenge ("bad-challenge" ).build ());
@@ -86,11 +87,29 @@ void setUp() {
8687 //region utilities
8788 @ SneakyThrows
8889 String generateWalletAddress () {
89- ECKeyPair ecKeyPair = Keys .createEcKeyPair ();
90- return Credentials .create (ecKeyPair ).getAddress ();
90+ final ECKeyPair otherKeyPair = Keys .createEcKeyPair ();
91+ return Credentials .create (otherKeyPair ).getAddress ();
9192 }
9293 //endregion
9394
95+ // region deprecated methods, to remove in future version
96+ @ Test
97+ void shouldCallGetTaskLogs () {
98+ final TaskController controller = spy (taskController );
99+ final String authorization = String .join ("_" , challenge .getHash (), signature , requesterAddress );
100+ controller .getTaskLogsLegacy (TASK_ID , authorization );
101+ verify (controller ).getTaskLogs (TASK_ID , authorization );
102+ }
103+
104+ @ Test
105+ void shouldCallGetComputeLogs () {
106+ final TaskController controller = spy (taskController );
107+ final String authorization = String .join ("_" , challenge .getHash (), signature , requesterAddress );
108+ controller .getComputeLogsLegacy (TASK_ID , WORKER_ADDRESS , authorization );
109+ verify (controller ).getComputeLogs (TASK_ID , WORKER_ADDRESS , authorization );
110+ }
111+ // endregion
112+
94113 //region getChallenge
95114 @ Test
96115 void shouldGetChallenge () {
@@ -193,7 +212,7 @@ void shouldBuildReplicateModelWithComputeLogs() {
193212 ReplicateModel dto = taskController .buildReplicateModel (entity );
194213 assertEquals (TASK_ID , dto .getChainTaskId ());
195214 assertTrue (dto .getSelf ().endsWith ("/tasks/0xtask/replicates/0xworker" ));
196- assertTrue (dto .getAppLogs ().endsWith ("/tasks/0xtask/replicates/0xworker/stdout " ));
215+ assertTrue (dto .getAppLogs ().endsWith ("/tasks/0xtask/replicates/0xworker/logs " ));
197216 }
198217 //endregion
199218
@@ -235,7 +254,6 @@ void shouldFailToGetTaskLogsWhenBadChallenge() {
235254 .build ();
236255 when (iexecHubService .getTaskDescription (TASK_ID )).thenReturn (description );
237256 when (challengeService .getChallenge (requesterAddress )).thenReturn (challenge );
238- when (taskLogsService .getComputeLogs (TASK_ID , WORKER_ADDRESS )).thenReturn (Optional .empty ());
239257 ResponseEntity <TaskLogsModel > response = taskController .getTaskLogs (TASK_ID , authorization );
240258 assertEquals (HttpStatus .UNAUTHORIZED , response .getStatusCode ());
241259 verify (iexecHubService ).getTaskDescription (TASK_ID );
@@ -256,7 +274,6 @@ void shouldFailToGetTaskLogsWhenNotTaskRequester() {
256274 .build ();
257275 String authorization = String .join ("_" , challenge .getHash (), signature , requesterAddress );
258276 when (iexecHubService .getTaskDescription (TASK_ID )).thenReturn (description );
259- when (challengeService .getChallenge (requesterAddress )).thenReturn (challenge );
260277 ResponseEntity <TaskLogsModel > response = taskController .getTaskLogs (TASK_ID , authorization );
261278 assertEquals (HttpStatus .FORBIDDEN , response .getStatusCode ());
262279 verify (iexecHubService ).getTaskDescription (TASK_ID );
@@ -301,7 +318,6 @@ void shouldFailToGetComputeLogsWhenBadChallenge() {
301318 .build ();
302319 when (iexecHubService .getTaskDescription (TASK_ID )).thenReturn (description );
303320 when (challengeService .getChallenge (requesterAddress )).thenReturn (challenge );
304- when (taskLogsService .getComputeLogs (TASK_ID , WORKER_ADDRESS )).thenReturn (Optional .empty ());
305321 ResponseEntity <ComputeLogs > response = taskController .getComputeLogs (TASK_ID , WORKER_ADDRESS , authorization );
306322 assertEquals (HttpStatus .UNAUTHORIZED , response .getStatusCode ());
307323 verify (iexecHubService ).getTaskDescription (TASK_ID );
@@ -322,7 +338,6 @@ void shouldFailToGetComputeLogsWhenNotTaskRequester() {
322338 .build ();
323339 String authorization = String .join ("_" , challenge .getHash (), signature , requesterAddress );
324340 when (iexecHubService .getTaskDescription (TASK_ID )).thenReturn (description );
325- when (challengeService .getChallenge (requesterAddress )).thenReturn (challenge );
326341 ResponseEntity <ComputeLogs > response = taskController .getComputeLogs (TASK_ID , WORKER_ADDRESS , authorization );
327342 assertEquals (HttpStatus .FORBIDDEN , response .getStatusCode ());
328343 verify (iexecHubService ).getTaskDescription (TASK_ID );
0 commit comments