Search in sources :

Example 26 with RestLiRequestData

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

the class TestBatchPatchArgumentBuilder method testArgumentBuilderSuccess.

@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, PatchRequest<MyComplexKey>[] patches) {
    Set<Object> batchKeys = new HashSet<Object>(Arrays.asList(keys));
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
    @SuppressWarnings("rawtypes") Parameter<BatchPatchRequest> param = new Parameter<BatchPatchRequest>("", BatchPatchRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, Collections.singletonList(param));
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, true, false);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
    RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchPatchRequest);
    Map<?, ?> data = ((BatchPatchRequest) args[0]).getData();
    assertEquals(data.size(), keys.length);
    for (int i = 0; i < keys.length; i++) {
        assertEquals(data.get(keys[i]), patches[i]);
    }
    verify(request, descriptor, context, routingResult);
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) HashSet(java.util.HashSet) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 27 with RestLiRequestData

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

the class TestActionArgumentBuilder method testKeyArguments.

@Test(dataProvider = "keyArgumentData")
public void testKeyArguments(List<Parameter<?>> params, MutablePathKeys pathKeys, Object[] expectedArgs) {
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, params, null, null);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(pathKeys, false, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"a\":\"xyz\",\"b\":123}", 3);
    RestLiArgumentBuilder argumentBuilder = new ActionArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args, expectedArgs);
    verify(descriptor, context, routingResult, request);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ResourceContext(com.linkedin.restli.server.ResourceContext) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Aggregations

RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)27 RestRequest (com.linkedin.r2.message.rest.RestRequest)24 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)24 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)22 Test (org.testng.annotations.Test)22 ResourceContext (com.linkedin.restli.server.ResourceContext)20 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)11 Parameter (com.linkedin.restli.internal.server.model.Parameter)10 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)9 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)9 AnnotationSet (com.linkedin.restli.internal.server.model.AnnotationSet)8 RoutingException (com.linkedin.restli.server.RoutingException)7 Annotation (java.lang.annotation.Annotation)6 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)4 CompoundKey (com.linkedin.restli.common.CompoundKey)4 Key (com.linkedin.restli.server.Key)4 HashSet (java.util.HashSet)4 IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)3 RequestContext (com.linkedin.r2.message.RequestContext)3 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)3