Skip to content

Commit

Permalink
chore(DataPlanePublicAPI): Error message handling
Browse files Browse the repository at this point in the history
 Added detailed assertions to an unit test should_returnListOfErrorsAsAResponse_if_anythingFails
  • Loading branch information
kkotowiczz committed Dec 16, 2024
1 parent 1f09a00 commit 9d909cf
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.edc.connector.dataplane.spi.iam.DataPlaneAuthorizationService;
import org.eclipse.edc.connector.dataplane.spi.pipeline.DataSource;
import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure;
import org.eclipse.edc.connector.dataplane.spi.pipeline.StreamResult;
import org.eclipse.edc.connector.dataplane.spi.resolver.DataAddressResolver;
import org.eclipse.edc.connector.dataplane.util.sink.AsyncStreamingDataSink;
Expand Down Expand Up @@ -49,6 +50,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.isA;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -123,19 +125,26 @@ void should_returnInternalServerError_if_transferFails() {
@Test
void should_returnListOfErrorsAsAResponse_if_anythingFails() {
var token = UUID.randomUUID().toString();
var errorMsg = UUID.randomUUID().toString();
var firstErrorMsg = UUID.randomUUID().toString();
var secondErrorMsg = UUID.randomUUID().toString();

when(dataAddressResolver.resolve(any())).thenReturn(Result.success(testDestAddress()));
when(pipelineService.transfer(any(), any()))
.thenReturn(completedFuture(StreamResult.error(errorMsg)));
.thenReturn(completedFuture(StreamResult.failure(new StreamFailure(List.of(firstErrorMsg, secondErrorMsg), StreamFailure.Reason.GENERAL_ERROR))));

baseRequest()
var jsonPath = baseRequest()
.header(AUTHORIZATION, token)
.when()
.post("/any")
.then()
.statusCode(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())
.contentType(JSON)
.body("errors", isA(List.class));
.body("errors", isA(List.class))
.extract()
.jsonPath();
var errors = jsonPath.getList("errors", String.class);
assertEquals(firstErrorMsg, errors.get(0));
assertEquals(secondErrorMsg, errors.get(1));
}

@Test
Expand Down

0 comments on commit 9d909cf

Please sign in to comment.