Search in sources :

Example 6 with IdEntityResponse

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

the class TestLatencyInstrumentation method makeUpstreamRequest.

/**
 * Make the "upstream" request (as opposed to the "downstream" request made from the resource method) using a set of
 * test parameters. Waits for the timing keys to be recorded by the {@link InstrumentationTrackingFilter} before
 * returning.
 * @param useStreaming parameter from the test method
 * @param forceException parameter from the test method
 */
private void makeUpstreamRequest(boolean useStreaming, boolean forceException, boolean useScatterGather) throws RemoteInvocationException, InterruptedException {
    InstrumentationControl instrumentationControl = new InstrumentationControl().setServiceUriPrefix(FILTERS_URI_PREFIX).setUseStreaming(useStreaming).setForceException(forceException).setUseScatterGather(useScatterGather);
    CreateIdEntityRequest<Long, InstrumentationControl> createRequest = new LatencyInstrumentationBuilders().createAndGet().input(instrumentationControl).build();
    ResponseFuture<IdEntityResponse<Long, InstrumentationControl>> response = getClient().sendRequest(createRequest);
    try {
        response.getResponseEntity();
        if (forceException) {
            Assert.fail("Forcing exception, should've failed.");
        }
    } catch (RestLiResponseException e) {
        if (e.getStatus() != 400) {
            Assert.fail("Server responded with a non-400 error: " + e.getServiceErrorStackTrace());
        }
        if (!forceException) {
            Assert.fail("Not forcing exception, didn't expect failure.");
        }
    }
    // Wait for the server to send the response and save the timings
    final boolean success = _countDownLatch.await(10, TimeUnit.SECONDS);
    if (!success) {
        Assert.fail("Request timed out!");
    }
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) InstrumentationControl(com.linkedin.restli.examples.instrumentation.api.InstrumentationControl) LatencyInstrumentationBuilders(com.linkedin.restli.examples.instrumentation.client.LatencyInstrumentationBuilders)

Example 7 with IdEntityResponse

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

the class TestParseqBasedFluentClientApiWithProjections method testCreateAndGetWithProjection.

@Test
public void testCreateAndGetWithProjection() throws Exception {
    CreateGreeting greetings = new CreateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    String msg = Double.toString(Math.random());
    CompletionStage<IdEntityResponse<Long, Greeting>> result = greetings.createAndGet(getGreeting(msg), optionalParams -> optionalParams.withMask(mask -> mask.withMessage()));
    CompletableFuture<IdEntityResponse<Long, Greeting>> future = result.toCompletableFuture();
    Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
    Assert.assertFalse(future.get().getEntity().hasId());
    Assert.assertFalse(future.get().getEntity().hasTone());
    Assert.assertEquals(msg, future.get().getEntity().getMessage());
}
Also used : IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) PagingMetadataProjections(com.linkedin.restli.examples.greetings.client.PagingMetadataProjections) Arrays(java.util.Arrays) RestLiValidationFilter(com.linkedin.restli.server.validation.RestLiValidationFilter) CollectionResponse(com.linkedin.restli.common.CollectionResponse) AutoValidationWithProjectionFluentClient(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionFluentClient) Test(org.testng.annotations.Test) PatchGenerator(com.linkedin.restli.client.util.PatchGenerator) EntityResponse(com.linkedin.restli.common.EntityResponse) Map(java.util.Map) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) ManualProjections(com.linkedin.restli.examples.greetings.client.ManualProjections) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) ParSeqRestliClientConfigBuilder(com.linkedin.restli.client.ParSeqRestliClientConfigBuilder) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) ParSeqRestliClientBuilder(com.linkedin.restli.client.ParSeqRestliClientBuilder) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) AutoValidationWithProjection(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjection) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) PatchRequest(com.linkedin.restli.common.PatchRequest) Assert(org.testng.Assert) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) ManualProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.ManualProjectionsFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ParSeqUnitTestHelper(com.linkedin.parseq.ParSeqUnitTestHelper) Tone(com.linkedin.restli.examples.greetings.api.Tone) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) AfterClass(org.testng.annotations.AfterClass) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) PagingMetadataProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.PagingMetadataProjectionsFluentClient) ParSeqRestliClient(com.linkedin.restli.client.ParSeqRestliClient) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) com.linkedin.restli.examples.greetings.api.myItem(com.linkedin.restli.examples.greetings.api.myItem) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) Sets(org.testng.collections.Sets) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Test(org.testng.annotations.Test)

Example 8 with IdEntityResponse

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

the class TestRestLiValidationWithProjection method provideProjectionWithValidFieldsBuilders.

@DataProvider
private Object[][] provideProjectionWithValidFieldsBuilders() throws DataProcessingException {
    List<PathSpec> spec = Arrays.asList(ValidationDemo.fields().stringB(), ValidationDemo.fields().includedB(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), // Add a wildcard for projecting the rest of the union members
    new PathSpec(ValidationDemo.fields().UnionFieldWithInlineRecord().getPathComponents(), PathSpec.WILDCARD), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), ValidationDemo.fields().MapWithTyperefs().values().id(), ValidationDemo.fields().validationDemoNext().intB());
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<>(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<ValidationDemo> getRequestWithArrayRange = wrapper.get().id(1).fields(ValidationDemo.fields().ArrayWithInlineRecord(10, 20)).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 }, { getRequestWithArrayRange, HttpStatus.S_200_OK }, { getAllRequest, HttpStatus.S_200_OK }, { createAndGetRequest, HttpStatus.S_201_CREATED }, { batchCreateAndGetRequest, HttpStatus.S_200_OK } };
}
Also used : BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) 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 9 with IdEntityResponse

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

the class TestReturnEntityWithCreate method testEntityWithProjection.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testEntityWithProjection(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().fields(Greeting.fields().tone(), Greeting.fields().id()).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(false, response.getEntity().getEntity().hasMessage());
    Assert.assertEquals(Tone.FRIENDLY, response.getEntity().getEntity().getTone());
}
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