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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations