Search in sources :

Example 11 with CreateKVResponse

use of com.linkedin.restli.server.CreateKVResponse in project rest.li by linkedin.

the class TestCreateResponseBuilder method returnEntityDataProvider.

@DataProvider(name = "returnEntityData")
public Object[][] returnEntityDataProvider() {
    CreateResponse createResponse = new CreateResponse(null, HttpStatus.S_201_CREATED);
    Foo entity = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
    CreateKVResponse<Integer, Foo> createKVResponse = new CreateKVResponse<>(null, entity);
    return new Object[][] { { createResponse, true, false }, { createResponse, false, false }, { createKVResponse, true, true }, { createKVResponse, false, false } };
}
Also used : CreateResponse(com.linkedin.restli.server.CreateResponse) Foo(com.linkedin.pegasus.generator.examples.Foo) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) DataProvider(org.testng.annotations.DataProvider)

Example 12 with CreateKVResponse

use of com.linkedin.restli.server.CreateKVResponse in project rest.li by linkedin.

the class TestCreateResponseBuilder method testProjectionInBuildRestLiResponseData.

@Test
public void testProjectionInBuildRestLiResponseData() throws URISyntaxException {
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
    ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
    EasyMock.expect(mockContext.isReturnEntityRequested()).andReturn(true);
    EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
    EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
    EasyMock.expect(mockContext.getRawRequestContext()).andReturn(new RequestContext()).anyTimes();
    EasyMock.expect(mockContext.getAlwaysProjectedFields()).andReturn(Collections.emptySet()).anyTimes();
    EasyMock.replay(mockContext);
    RoutingResult routingResult = new RoutingResult(mockContext, null);
    Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
    CreateKVResponse<Integer, Foo> values = new CreateKVResponse<>(null, value);
    CreateResponseBuilder responseBuilder = new CreateResponseBuilder();
    RestLiResponseData<CreateResponseEnvelope> envelope = responseBuilder.buildRestLiResponseData(new RestRequestBuilder(new URI("/foo")).build(), routingResult, values, Collections.emptyMap(), Collections.emptyList());
    RecordTemplate record = envelope.getResponseEnvelope().getRecord();
    Assert.assertEquals(record.data().size(), 1);
    Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
    Assert.assertTrue(envelope.getResponseEnvelope().isGetAfterCreate());
    EasyMock.verify(mockContext);
}
Also used : Foo(com.linkedin.pegasus.generator.examples.Foo) PathSpec(com.linkedin.data.schema.PathSpec) URI(java.net.URI) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RecordTemplate(com.linkedin.data.template.RecordTemplate) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) Test(org.testng.annotations.Test)

Example 13 with CreateKVResponse

use of com.linkedin.restli.server.CreateKVResponse in project rest.li by linkedin.

the class TestBatchCreateResponseBuilder method provideReturnEntityData.

@DataProvider(name = "returnEntityData")
public Object[][] provideReturnEntityData() {
    CreateResponse createResponse = new CreateResponse(1L, HttpStatus.S_201_CREATED);
    List<CreateResponse> createResponses = new ArrayList<>();
    createResponses.add(createResponse);
    BatchCreateResult<Long, Foo> batchCreateResult = new BatchCreateResult<>(createResponses);
    Foo entity = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
    CreateKVResponse<Long, Foo> createKVResponse = new CreateKVResponse<>(1L, entity);
    List<CreateKVResponse<Long, Foo>> createKVResponses = new ArrayList<>();
    createKVResponses.add(createKVResponse);
    BatchCreateKVResult<Long, Foo> batchCreateKVResult = new BatchCreateKVResult<>(createKVResponses);
    return new Object[][] { { batchCreateResult, createResponses, true, false }, { batchCreateResult, createResponses, false, false }, { batchCreateKVResult, createKVResponses, true, true }, { batchCreateKVResult, createKVResponses, false, false } };
}
Also used : CreateResponse(com.linkedin.restli.server.CreateResponse) Foo(com.linkedin.pegasus.generator.examples.Foo) ArrayList(java.util.ArrayList) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) BatchCreateKVResult(com.linkedin.restli.server.BatchCreateKVResult) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) DataProvider(org.testng.annotations.DataProvider)

Aggregations

CreateKVResponse (com.linkedin.restli.server.CreateKVResponse)13 Foo (com.linkedin.pegasus.generator.examples.Foo)7 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)6 BatchCreateKVResult (com.linkedin.restli.server.BatchCreateKVResult)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)6 ArrayList (java.util.ArrayList)6 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)5 CreateResponse (com.linkedin.restli.server.CreateResponse)5 URI (java.net.URI)5 Test (org.testng.annotations.Test)5 DataMap (com.linkedin.data.DataMap)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 PathSpec (com.linkedin.data.schema.PathSpec)3 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)3 RequestContext (com.linkedin.r2.message.RequestContext)3 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)3 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)3 ReturnEntity (com.linkedin.restli.server.annotations.ReturnEntity)3 UriBuilder (com.linkedin.jersey.api.uri.UriBuilder)2