Search in sources :

Example 1 with CustomDouble

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());
    }
}
Also used : UriRef(com.linkedin.restli.examples.typeref.api.UriRef) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) CustomDouble(com.linkedin.restli.examples.custom.types.CustomDouble) CustomDoubleRef(com.linkedin.restli.examples.typeref.api.CustomDoubleRef) URI(java.net.URI) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) GetRequestBuilder(com.linkedin.restli.client.GetRequestBuilder) Test(org.testng.annotations.Test)

Aggregations

GetRequestBuilder (com.linkedin.restli.client.GetRequestBuilder)1 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)1 CompoundKey (com.linkedin.restli.common.CompoundKey)1 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)1 CustomDouble (com.linkedin.restli.examples.custom.types.CustomDouble)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 CustomDoubleRef (com.linkedin.restli.examples.typeref.api.CustomDoubleRef)1 UriRef (com.linkedin.restli.examples.typeref.api.UriRef)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1