use of com.linkedin.restli.examples.custom.types.CustomDouble in project rest.li by linkedin.
the class TestTyperefCustomDoubleAssociationKeyResource method testGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException, URISyntaxException {
HashMap<String, CompoundKey.TypeInfo> keyParts = new HashMap<>();
keyParts.put("src", new CompoundKey.TypeInfo(CustomDouble.class, CustomDoubleRef.class));
keyParts.put("dest", new CompoundKey.TypeInfo(URI.class, UriRef.class));
GetRequestBuilder<CompoundKey, Message> getBuilder = new GetRequestBuilder<>("typerefCustomDoubleAssociationKeyResource", Message.class, new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET), new HashMap<>(), new HashMap<>(), CompoundKey.class, null, null, Message.class, keyParts), requestOptions);
final String[] stringArray = { "foo" };
GetRequest<Message> req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.0)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
Message result = resp.getEntity();
Assert.assertEquals(result.getId(), "100.0->www.linkedin.com");
Assert.assertEquals(result.getMessage(), String.format("I need some $20. Array contents %s.", Arrays.asList(stringArray)));
// key validation failure scenario
try {
req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.02)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
REST_CLIENT.sendRequest(req).getResponse();
} catch (RestLiResponseException ex) {
Assert.assertEquals(ex.getServiceErrorMessage(), "Input field validation failure, reason: ERROR :: :: \"100.02\" does not match [0-9]*\\.[0-9]\n");
Assert.assertEquals(ex.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
}
}
Aggregations