Search in sources :

Example 16 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestRestLiValidationFromClient method testCreateSuccess.

@Test(dataProvider = "provideCreateSuccessData")
public void testCreateSuccess(Object builder, ValidationDemo validationDemo) {
    ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).create().validateInput(validationDemo);
    Assert.assertEquals(result.isValid(), true);
}
Also used : RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) Test(org.testng.annotations.Test)

Example 17 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestStreamingGreetings method resourceMethodDoesNotAcceptAttachments.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void resourceMethodDoesNotAcceptAttachments(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    //Resource method does not desire request attachments. Assert that all the attachments are drained and that a 400
    //bad request is observed.
    final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copyString("clientData", Charset.defaultCharset()));
    RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, Object> methodBuilderWrapper = builders.action("actionNoAttachmentsAllowed");
    methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
    final Request<Object> request = methodBuilderWrapper.build();
    try {
        getClient().sendRequest(request).getResponse().getEntity();
        Assert.fail();
    } catch (final RestLiResponseException responseException) {
        Assert.assertEquals(responseException.getStatus(), 400);
        Assert.assertEquals(responseException.getServiceErrorMessage(), "Resource method endpoint invoked does not accept any request attachments.");
    }
    //Then verify the response and request attachments were fully absorbed.
    Assert.assertTrue(greetingAttachment.finished());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) Test(org.testng.annotations.Test)

Example 18 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestRestLiValidationFromClient method testPartialUpdateFailure.

@Test(dataProvider = "providePartialUpdateFailureData")
public void testPartialUpdateFailure(Object builder, String patch, String errorMessage) {
    PatchRequest<ValidationDemo> patchRequest = PatchBuilder.buildPatchFromString(patch);
    ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).partialUpdate().validateInput(patchRequest);
    Assert.assertEquals(result.isValid(), false);
    Assert.assertEquals(result.getMessages().toString(), errorMessage);
}
Also used : RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 19 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestGreetingsClient method createBatchTestDataSerially.

/**
   * Creates batch data.
   *
   * @param greetings the greetings that we want to create
   *
   * @return the ids of the created Greetings
   * @throws RemoteInvocationException
   */
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
    List<Long> createdIds = new ArrayList<Long>();
    for (Greeting greeting : greetings) {
        RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
        Long createdId;
        if (createBuilder.isRestLi2Builder()) {
            Object objBuilder = createBuilder.getBuilder();
            @SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
            CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
            Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
            createdId = response.getEntity().getId();
        } else {
            Request<EmptyRecord> request = createBuilder.input(greeting).build();
            Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
            @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
            createdId = createResponse.getId();
        }
        createdIds.add(createdId);
    }
    return createdIds;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ArrayList(java.util.ArrayList) CreateIdRequestBuilder(com.linkedin.restli.client.CreateIdRequestBuilder)

Aggregations

RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)19 Test (org.testng.annotations.Test)16 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)8 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)7 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)3 CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 CreateResponse (com.linkedin.restli.client.response.CreateResponse)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 IdResponse (com.linkedin.restli.common.IdResponse)2 RestLiTestAttachmentDataSource (com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 DataMap (com.linkedin.data.DataMap)1 PathSpec (com.linkedin.data.schema.PathSpec)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)1