Skip to content

Commit

Permalink
Modify ConjureBodySerDeTest#testErrorsDecoded to test e2e error decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritham Marupaka committed Jan 7, 2025
1 parent c70024f commit 1b7342d
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.palantir.conjure.java.api.errors.ErrorType;
import com.palantir.conjure.java.api.errors.RemoteException;
import com.palantir.conjure.java.api.errors.SerializableError;
import com.palantir.conjure.java.api.errors.ServiceException;
import com.palantir.conjure.java.serialization.ObjectMappers;
import com.palantir.dialogue.BinaryRequestBody;
import com.palantir.dialogue.BodySerDe;
import com.palantir.dialogue.RequestBody;
Expand All @@ -47,6 +50,7 @@
@ExtendWith(MockitoExtension.class)
public class ConjureBodySerDeTest {

private static final ObjectMapper SERVER_MAPPER = ObjectMappers.newServerObjectMapper();
private static final TypeMarker<String> TYPE = new TypeMarker<String>() {};
private static final TypeMarker<Optional<String>> OPTIONAL_TYPE = new TypeMarker<Optional<String>>() {};

Expand Down Expand Up @@ -137,14 +141,12 @@ public void testRequestUnknownContentType() throws IOException {
}

@Test
public void testErrorsDecoded() {
TestResponse response = new TestResponse().code(400);

public void testErrorsDecoded() throws JsonProcessingException {
ServiceException serviceException = new ServiceException(ErrorType.INVALID_ARGUMENT);
SerializableError serialized = SerializableError.forException(serviceException);
errorDecoder = mock(ErrorDecoder.class);
when(errorDecoder.isError(response)).thenReturn(true);
when(errorDecoder.decode(response)).thenReturn(new RemoteException(serialized, 400));
TestResponse response = TestResponse.withBody(SERVER_MAPPER.writeValueAsString(serialized))
.code(400)
.contentType("application/json");

BodySerDe serializers = conjureBodySerDe("text/plain");

Expand Down

0 comments on commit 1b7342d

Please sign in to comment.