use of com.linkedin.restli.common.IdEntityResponse 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.IdEntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateReturnEntity.
@Test
public void testCreateReturnEntity() throws Exception {
CreateGreeting greetings = new CreateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
String msg = Double.toString(Math.random());
CompletionStage<IdEntityResponse<Long, Greeting>> result = greetings.createAndGet(getGreeting(msg));
CompletableFuture<IdEntityResponse<Long, Greeting>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertEquals(msg, future.get().getEntity().getMessage());
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testReturnEntityOnDemand.
/**
* Ensures that different usages of {@link com.linkedin.restli.client.CreateIdEntityRequestBuilder#returnEntity(boolean)} are handled
* correctly and that the response appropriately contains the entity or nothing depending on how and if the provided
* method is used.
*/
@Test(dataProvider = "returnEntityOnDemandData")
public void testReturnEntityOnDemand(Boolean returnEntity, boolean expectReturnEntity) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
CreateGreetingRequestBuilders builders = new CreateGreetingRequestBuilders();
CreateGreetingCreateAndGetRequestBuilder builder = builders.createAndGet().input(greeting);
if (returnEntity != null) {
builder.returnEntity(returnEntity);
}
CreateIdEntityRequest<Long, Greeting> createIdEntityRequest = builder.build();
Response<IdEntityResponse<Long, Greeting>> response = getClient().sendRequest(createIdEntityRequest).getResponse();
long id = response.getEntity().getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + CreateGreetingRequestBuilders.getPrimaryResource() + "/" + id);
Assert.assertEquals(id, Long.parseLong(stringId));
if (expectReturnEntity) {
Greeting returnedEntity = response.getEntity().getEntity();
Assert.assertNotNull(returnedEntity, "RecordTemplate entity in response should not be null.");
Assert.assertEquals(returnedEntity.getMessage(), greeting.getMessage(), "Expect returned entity message to match original.");
Assert.assertEquals(returnedEntity.getTone(), greeting.getTone(), "Expect returned entity tone to match original.");
} else {
Assert.assertNull(response.getEntity().getEntity(), "RecordTemplate entity in response should be null.");
}
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestRestLiValidation method testCreateAndGetAutoSuccess.
@Test(dataProvider = "provideCreateAndGetSuccessData")
@SuppressWarnings("unchecked")
public void testCreateAndGetAutoSuccess(RestClient restClient, Object builder, ValidationDemo validationDemo) throws RemoteInvocationException {
Request<IdEntityResponse<Integer, ValidationDemo>> createRequest = new RootBuilderWrapper<Integer, ValidationDemo>(builder).createAndGet().input(validationDemo).build();
Response<IdEntityResponse<Integer, ValidationDemo>> response = restClient.sendRequest(createRequest).getResponse();
ValidationDemo.UnionFieldWithInlineRecord unionField = new ValidationDemo.UnionFieldWithInlineRecord();
unionField.setMyEnum(myEnum.FOOFOO);
ValidationDemo expected = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(unionField);
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(response.getEntity().getEntity(), expected);
}
use of com.linkedin.restli.common.IdEntityResponse in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testCreateIdEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testCreateIdEntity(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
CreateIdEntityRequest<Long, Greeting> createIdEntityRequest = builders.createAndGet().input(greeting).build();
Response<IdEntityResponse<Long, Greeting>> response = restClient.sendRequest(createIdEntityRequest).getResponse();
long id = response.getEntity().getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id);
Assert.assertEquals(id, Long.parseLong(stringId));
Assert.assertEquals("second time!", response.getEntity().getEntity().getMessage());
}
Aggregations