Search in sources :

Example 41 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestCollectionResponseBuilder method testBuilderExceptions.

@Test(dataProvider = "exceptionTestData")
public void testBuilderExceptions(Object results, String expectedErrorMessage) throws URISyntaxException {
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    ResourceContext mockContext = getMockResourceContext(null, null, null, null, null);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
    try {
        responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, results, headers, Collections.<HttpCookie>emptyList());
        Assert.fail("An exception should have been thrown because of null elements!");
    } catch (RestLiServiceException e) {
        Assert.assertTrue(e.getMessage().contains(expectedErrorMessage));
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Test(org.testng.annotations.Test)

Example 42 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestCollectionResponseBuilder method getMockResourceMethodDescriptor.

private static ResourceMethodDescriptor getMockResourceMethodDescriptor() {
    ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
    EasyMock.expect(mockDescriptor.getParametersWithType(EasyMock.<Parameter.ParamType>anyObject())).andReturn(Collections.<Parameter<?>>emptyList()).once();
    EasyMock.replay(mockDescriptor);
    return mockDescriptor;
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Parameter(com.linkedin.restli.internal.server.model.Parameter)

Example 43 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestCollectionResponseBuilder method getMockResourceMethodDescriptor.

private static ResourceMethodDescriptor getMockResourceMethodDescriptor(ResourceMethod resourceMethod) {
    ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
    EasyMock.expect(mockDescriptor.getParametersWithType(EasyMock.<Parameter.ParamType>anyObject())).andReturn(Collections.<Parameter<?>>emptyList()).once();
    EasyMock.expect(mockDescriptor.getType()).andReturn(resourceMethod);
    EasyMock.replay(mockDescriptor);
    return mockDescriptor;
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Parameter(com.linkedin.restli.internal.server.model.Parameter)

Example 44 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestCreateResponseBuilder method testBuilder.

@Test(dataProvider = "testData")
public void testBuilder(ProtocolVersion protocolVersion, Object expectedId, String expectedLocation, String expectedHeaderId, String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap) throws URISyntaxException {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey);
    IdResponse<?> expectedIdResponse = new IdResponse<Object>(expectedId);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
    // the headers passed in are modified
    Map<String, String> expectedHeaders = new HashMap<String, String>(headers);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
    ResourceContext mockContext = getMockResourceContext(protocolVersion, altKeyName);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    CreateResponseBuilder createResponseBuilder = new CreateResponseBuilder();
    RestLiResponseData responseData = createResponseBuilder.buildRestLiResponseData(restRequest, routingResult, createResponse, headers, Collections.<HttpCookie>emptyList());
    Assert.assertFalse(responseData.getCreateResponseEnvelope().isGetAfterCreate());
    PartialRestResponse partialRestResponse = createResponseBuilder.buildResponse(routingResult, responseData);
    expectedHeaders.put(RestConstants.HEADER_LOCATION, expectedLocation);
    if (protocolVersion.equals(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion())) {
        expectedHeaders.put(RestConstants.HEADER_ID, expectedHeaderId);
    } else {
        expectedHeaders.put(RestConstants.HEADER_RESTLI_ID, expectedHeaderId);
    }
    EasyMock.verify(mockContext, mockDescriptor);
    ResponseBuilderUtil.validateHeaders(partialRestResponse, expectedHeaders);
    Assert.assertEquals(partialRestResponse.getStatus(), HttpStatus.S_201_CREATED);
    Assert.assertEquals(partialRestResponse.getEntity(), expectedIdResponse);
}
Also used : IdResponse(com.linkedin.restli.common.IdResponse) ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) CreateResponse(com.linkedin.restli.server.CreateResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) URI(java.net.URI) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) Test(org.testng.annotations.Test)

Example 45 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestCreateResponseBuilder method testBuilderException.

@Test
public void testBuilderException() throws URISyntaxException {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey, null);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
    ResourceContext mockContext = getMockResourceContext(protocolVersion, null);
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
    CreateResponseBuilder createResponseBuilder = new CreateResponseBuilder();
    try {
        createResponseBuilder.buildRestLiResponseData(restRequest, routingResult, createResponse, headers, Collections.<HttpCookie>emptyList());
        Assert.fail("buildRestLiResponseData should have thrown an exception because the status is null!");
    } catch (RestLiServiceException e) {
        Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a CreateResponse from the resource method: "));
    }
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) CompoundKey(com.linkedin.restli.common.CompoundKey) CreateResponse(com.linkedin.restli.server.CreateResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) URI(java.net.URI) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) Test(org.testng.annotations.Test)

Aggregations

ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)195 Test (org.testng.annotations.Test)171 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)140 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)116 AfterTest (org.testng.annotations.AfterTest)105 BeforeTest (org.testng.annotations.BeforeTest)105 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)66 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)47 RestRequest (com.linkedin.r2.message.rest.RestRequest)41 ByteString (com.linkedin.data.ByteString)40 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)38 ResourceContext (com.linkedin.restli.server.ResourceContext)37 CustomString (com.linkedin.restli.server.custom.types.CustomString)37 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)31 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)27 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)27 EasyMock.anyObject (org.easymock.EasyMock.anyObject)27 Callback (com.linkedin.common.callback.Callback)26 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)26 CustomStatusCollectionResource (com.linkedin.restli.server.twitter.CustomStatusCollectionResource)26