Search in sources :

Example 1 with IdEntityResponse

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 } };
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) PathSpec(com.linkedin.data.schema.PathSpec) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) DataProvider(org.testng.annotations.DataProvider)

Example 2 with IdEntityResponse

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());
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Test(org.testng.annotations.Test)

Example 3 with IdEntityResponse

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.");
    }
}
Also used : BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CreateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.CreateGreetingRequestBuilders) CreateGreetingCreateAndGetRequestBuilder(com.linkedin.restli.examples.greetings.client.CreateGreetingCreateAndGetRequestBuilder) Test(org.testng.annotations.Test)

Example 4 with IdEntityResponse

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);
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 5 with IdEntityResponse

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());
}
Also used : BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Test(org.testng.annotations.Test)

Aggregations

IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)9 Test (org.testng.annotations.Test)6 BatchCreateIdEntityResponse (com.linkedin.restli.common.BatchCreateIdEntityResponse)5 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)4 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)3 PathSpec (com.linkedin.data.schema.PathSpec)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)2 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)2 CreateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient)2 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)1 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)1 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)1 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)1 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)1 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)1 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)1 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)1 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)1