-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decode errors during deserialization #113
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,18 @@ | |
package com.palantir.conjure.java.dialogue.serde; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
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.dialogue.BodySerDe; | ||
import com.palantir.dialogue.ErrorDecoder; | ||
import com.palantir.dialogue.RequestBody; | ||
import com.palantir.dialogue.Response; | ||
import com.palantir.dialogue.TypeMarker; | ||
|
@@ -35,11 +42,17 @@ | |
import java.util.Map; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ConjureBodySerDeTest { | ||
|
||
private static final TypeMarker<String> TYPE = new TypeMarker<String>() {}; | ||
|
||
@Mock private ErrorDecoder errorDecoder; | ||
|
||
@Test | ||
public void testRequestContentType() throws IOException { | ||
Encoding json = new StubEncoding("application/json"); | ||
|
@@ -103,6 +116,23 @@ public void testResponseUnknownContentType() throws IOException { | |
assertThat(body.contentType()).isEqualTo(json.getContentType()); | ||
} | ||
|
||
@Test | ||
public void testErrorsDecoded() { | ||
TestResponse response = new TestResponse(); | ||
// response.contentType(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh? |
||
response.code = 400; | ||
|
||
ServiceException serviceException = new ServiceException(ErrorType.INVALID_ARGUMENT); | ||
SerializableError serialized = SerializableError.forException(serviceException); | ||
when(errorDecoder.isError(response)).thenReturn(true); | ||
when(errorDecoder.decode(response)).thenReturn(new RemoteException(serialized, 400)); | ||
|
||
BodySerDe serializers = new ConjureBodySerDe(ImmutableList.of(new StubEncoding("text/plain")), errorDecoder); | ||
|
||
assertThatExceptionOfType(RemoteException.class) | ||
.isThrownBy(() -> serializers.deserializer(TYPE).deserialize(response)); | ||
} | ||
|
||
/** Deserializes requests as the configured content type. */ | ||
public static final class StubEncoding implements Encoding { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course