use of com.linkedin.restli.common.BatchCreateIdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateWithEntityWithError.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testBatchCreateWithEntityWithError(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("good!");
greeting.setTone(Tone.FRIENDLY);
Greeting greeting2 = new Greeting();
greeting2.setMessage("too much!");
greeting2.setTone(Tone.FRIENDLY);
List<Greeting> greetings = new ArrayList<Greeting>(Arrays.asList(greeting, greeting, greeting, greeting2));
BatchCreateIdEntityRequest<Long, Greeting> batchCreateIdEntityRequest = builders.batchCreateAndGet().inputs(greetings).build();
Response<BatchCreateIdEntityResponse<Long, Greeting>> response = restClient.sendRequest(batchCreateIdEntityRequest).getResponse();
BatchCreateIdEntityResponse<Long, Greeting> entityResponses = response.getEntity();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
int numOfElem = 0;
for (CreateIdEntityStatus<?, ?> singleResponse : entityResponses.getElements()) {
if (numOfElem > 2) {
Assert.assertTrue(singleResponse.hasError());
Assert.assertEquals(singleResponse.getStatus().intValue(), HttpStatus.S_400_BAD_REQUEST.getCode());
// More than 3 elements were sent, should trigger exception.
Assert.assertEquals(singleResponse.getError().getMessage(), "exceed quota");
} else {
@SuppressWarnings("deprecation") String id = singleResponse.getId();
Assert.assertNotNull(id);
Greeting entity = (Greeting) singleResponse.getEntity();
Assert.assertEquals(Tone.FRIENDLY, entity.getTone());
Assert.assertEquals(singleResponse.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
}
numOfElem++;
}
}
use of com.linkedin.restli.common.BatchCreateIdEntityResponse in project rest.li by linkedin.
the class TestResLiValidationWithProjection method provideProjectionWithValidFieldsBuilders.
@DataProvider
private Object[][] provideProjectionWithValidFieldsBuilders() throws DataProcessingException {
List<PathSpec> spec = Arrays.asList(ValidationDemo.fields().stringB(), ValidationDemo.fields().includedB(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), ValidationDemo.fields().MapWithTyperefs().values().id(), ValidationDemo.fields().validationDemoNext().intB());
RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<Integer, ValidationDemo>(new AutoValidationWithProjectionBuilders());
Request<CollectionResponse<ValidationDemo>> findRequest = wrapper.findBy("searchWithProjection").fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<ValidationDemo> getRequest = wrapper.get().id(1).fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<CollectionResponse<ValidationDemo>> getAllRequest = wrapper.getAll().fields(spec.toArray(new PathSpec[spec.size()])).build();
// Valid input for CreateAndGet
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.FOOFOO);
ValidationDemo validDemo = new ValidationDemo().setStringB("b").setUnionFieldWithInlineRecord(unionField);
Request<IdEntityResponse<Integer, ValidationDemo>> createAndGetRequest = wrapper.createAndGet().input(validDemo).fields(spec.toArray(new PathSpec[spec.size()])).build();
Request<BatchCreateIdEntityResponse<Integer, ValidationDemo>> batchCreateAndGetRequest = wrapper.batchCreateAndGet().inputs(Arrays.asList(validDemo)).fields(spec.toArray(new PathSpec[spec.size()])).build();
return new Object[][] { { findRequest, HttpStatus.S_200_OK }, { getRequest, HttpStatus.S_200_OK }, { getAllRequest, HttpStatus.S_200_OK }, { createAndGetRequest, HttpStatus.S_201_CREATED }, { batchCreateAndGetRequest, HttpStatus.S_200_OK } };
}
use of com.linkedin.restli.common.BatchCreateIdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateEntityWithProjection.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testBatchCreateEntityWithProjection(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("projection time!");
greeting.setTone(Tone.FRIENDLY);
BatchCreateIdEntityRequest<Long, Greeting> batchCreateIdEntityRequest = builders.batchCreateAndGet().fields(Greeting.fields().tone(), Greeting.fields().id()).inputs(Arrays.asList(greeting, greeting)).build();
Response<BatchCreateIdEntityResponse<Long, Greeting>> response = restClient.sendRequest(batchCreateIdEntityRequest).getResponse();
BatchCreateIdEntityResponse<Long, Greeting> entityResponses = response.getEntity();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
for (CreateIdEntityStatus<?, ?> singleResponse : entityResponses.getElements()) {
@SuppressWarnings("deprecation") String id = singleResponse.getId();
Assert.assertNotNull(id);
Greeting entity = (Greeting) singleResponse.getEntity();
Assert.assertEquals(false, entity.hasMessage());
Assert.assertEquals(true, entity.hasId());
Assert.assertEquals(Tone.FRIENDLY, entity.getTone());
}
}
use of com.linkedin.restli.common.BatchCreateIdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateWithEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testBatchCreateWithEntity(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
Greeting greeting2 = new Greeting();
greeting2.setMessage("first time!");
greeting2.setTone(Tone.FRIENDLY);
List<Greeting> greetings = new ArrayList<Greeting>();
greetings.add(greeting);
greetings.add(greeting2);
BatchCreateIdEntityRequest<Long, Greeting> batchCreateIdEntityRequest = builders.batchCreateAndGet().inputs(greetings).build();
Response<BatchCreateIdEntityResponse<Long, Greeting>> response = restClient.sendRequest(batchCreateIdEntityRequest).getResponse();
BatchCreateIdEntityResponse<Long, Greeting> entityResponses = response.getEntity();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
for (CreateIdEntityStatus<?, ?> singleResponse : entityResponses.getElements()) {
@SuppressWarnings("deprecation") String id = singleResponse.getId();
Assert.assertNotNull(id);
Greeting entity = (Greeting) singleResponse.getEntity();
Assert.assertEquals(Tone.FRIENDLY, entity.getTone());
Assert.assertEquals(singleResponse.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
}
}
Aggregations