Search in sources :

Example 56 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomMetadataProjection method testRootAutomaticMetadataAutomaticSingleRootEmptyMeta.

/**
   * Calls the resource method rootAutomaticMetadataAutomatic with and a single root object and empty fields list for
   * metadata. This will leave just the query string parameter by itself in the URI, e.g "...&metadataFields&...
   */
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootAutomaticMetadataAutomaticSingleRootEmptyMeta(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    final Request<CollectionResponse<Greeting>> request = builders.findBy("rootAutomaticMetadataAutomatic").fields(Greeting.fields().tone()).metadataFields().build();
    final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    assertEntityElements(response.getEntity().getElements(), true, /*hasTone*/
    false, /*hasMessage*/
    false);
    final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
    //Nothing should be sent back here
    assertCustomMetadata(metadataGreeting, false, /*hasTone*/
    false, /*hasMessage*/
    false);
    Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
    assertAllPagingFieldsExist(response.getEntity().getPaging());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 57 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testIPAddressQueryParam.

// This tests that a typeref that refers to bytes with a custom coercer is serialized correctly when used as a query parameter.
// (See IPAddressSimple.pdsc)
@Test
public void testIPAddressQueryParam() throws RemoteInvocationException, UnknownHostException {
    FindRequest<Greeting> findRequest = new CustomTypesRequestBuilders().findByIp().ipParam(Inet4Address.getByName("linkedin.com")).build();
    Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    Assert.assertEquals(response.getEntity().getElements().size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypesRequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypesRequestBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Test(org.testng.annotations.Test)

Example 58 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testCalendarRefArrayQueryParam.

@Test
public void testCalendarRefArrayQueryParam() throws RemoteInvocationException {
    FindRequest<Greeting> findRequest = new CustomTypesRequestBuilders().findByCalendars().addCalendarsParam(new GregorianCalendar()).build();
    Response<CollectionResponse<Greeting>> response = getClient().sendRequest(findRequest).getResponse();
    Assert.assertEquals(response.getEntity().getElements().size(), 0);
    CalendarRefArray calendarRefArray = new CalendarRefArray();
    calendarRefArray.add(new GregorianCalendar());
    findRequest = new CustomTypesRequestBuilders().findByCalendars().calendarsParam(calendarRefArray).build();
    response = getClient().sendRequest(findRequest).getResponse();
    Assert.assertEquals(response.getEntity().getElements().size(), 0);
    List<Calendar> calendars = new ArrayList<Calendar>();
    calendars.add(new GregorianCalendar());
    findRequest = new CustomTypesRequestBuilders().findByCalendars().calendarsParam(calendars).build();
    response = getClient().sendRequest(findRequest).getResponse();
    Assert.assertEquals(response.getEntity().getElements().size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CustomTypesRequestBuilders(com.linkedin.restli.examples.greetings.client.CustomTypesRequestBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) CalendarRefArray(com.linkedin.restli.examples.typeref.api.CalendarRefArray) Test(org.testng.annotations.Test)

Example 59 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestExceptionsResource method testBatchCreateErrors.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchCreateErrors(RestliRequestOptions requestOptions) throws Exception {
    ExceptionsBuilders builders = new ExceptionsBuilders(requestOptions);
    Request<CollectionResponse<CreateStatus>> batchCreateRequest = builders.batchCreate().input(new Greeting().setId(10L).setMessage("Greetings.").setTone(Tone.SINCERE)).input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
    Response<CollectionResponse<CreateStatus>> response = getClient().sendRequest(batchCreateRequest).getResponse();
    List<CreateStatus> createStatuses = response.getEntity().getElements();
    Assert.assertEquals(createStatuses.size(), 2);
    @SuppressWarnings("unchecked") CreateIdStatus<Long> status0 = (CreateIdStatus<Long>) createStatuses.get(0);
    Assert.assertEquals(status0.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
    Assert.assertEquals(status0.getKey(), new Long(10));
    @SuppressWarnings("deprecation") String id = status0.getId();
    Assert.assertEquals(BatchResponse.keyToString(status0.getKey(), ProtocolVersionUtil.extractProtocolVersion(response.getHeaders())), id);
    Assert.assertFalse(status0.hasError());
    CreateStatus status1 = createStatuses.get(1);
    Assert.assertEquals(status1.getStatus().intValue(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
    Assert.assertTrue(status1.hasError());
    ErrorResponse error = status1.getError();
    Assert.assertEquals(error.getStatus().intValue(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
    Assert.assertEquals(error.getMessage(), "I will not tolerate your insolence!");
    Assert.assertEquals(error.getServiceErrorCode().intValue(), 999);
    Assert.assertEquals(error.getExceptionClass(), "com.linkedin.restli.server.RestLiServiceException");
    Assert.assertEquals(error.getErrorDetails().data().getString("reason"), "insultingGreeting");
    Assert.assertTrue(error.getStackTrace().startsWith("com.linkedin.restli.server.RestLiServiceException [HTTP Status:406, serviceErrorCode:999]: I will not tolerate your insolence!"), "stacktrace mismatch:" + error.getStackTrace());
}
Also used : CreateStatus(com.linkedin.restli.common.CreateStatus) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ExceptionsBuilders(com.linkedin.restli.examples.greetings.client.ExceptionsBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 60 with CollectionResponse

use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.

the class TestCustomTypesClient method testCustomLongArray.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCustomLongArray(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    List<CustomLong> ls = new ArrayList<CustomLong>(2);
    ls.add(new CustomLong(1L));
    ls.add(new CustomLong(2L));
    Request<CollectionResponse<Greeting>> request = builders.findBy("CustomLongArray").setQueryParam("ls", ls).build();
    List<Greeting> elements = getClient().sendRequest(request).getResponse().getEntity().getElements();
    Assert.assertEquals(elements.size(), 0);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResponse(com.linkedin.restli.common.CollectionResponse) ArrayList(java.util.ArrayList) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Test(org.testng.annotations.Test)

Aggregations

CollectionResponse (com.linkedin.restli.common.CollectionResponse)85 Test (org.testng.annotations.Test)77 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)58 CreateStatus (com.linkedin.restli.common.CreateStatus)11 ArrayList (java.util.ArrayList)7 DataMap (com.linkedin.data.DataMap)6 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)6 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)5 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)5 UpdateStatus (com.linkedin.restli.common.UpdateStatus)5 HttpStatus (com.linkedin.restli.common.HttpStatus)4 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)4 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)4 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)4 HashMap (java.util.HashMap)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 Link (com.linkedin.restli.common.Link)3 Message (com.linkedin.restli.examples.greetings.api.Message)3 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)3 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)3