Search in sources :

Example 1 with BatchCreateIdEntityResponse

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

Example 2 with BatchCreateIdEntityResponse

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 } };
}
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 3 with BatchCreateIdEntityResponse

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

Example 4 with BatchCreateIdEntityResponse

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

Aggregations

BatchCreateIdEntityResponse (com.linkedin.restli.common.BatchCreateIdEntityResponse)4 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 Test (org.testng.annotations.Test)3 ArrayList (java.util.ArrayList)2 PathSpec (com.linkedin.data.schema.PathSpec)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)1 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)1 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)1 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)1 DataProvider (org.testng.annotations.DataProvider)1