Search in sources :

Example 1 with IntegerDataSchema

use of com.linkedin.data.schema.IntegerDataSchema in project rest.li by linkedin.

the class TestBatchPatchArgumentBuilder method failureData.

@DataProvider
private Object[][] failureData() {
    Object[] compoundKeys = new Object[] { new CompoundKey().append("string1", "apples").append("string2", "oranges"), new CompoundKey().append("string1", "XYZ").append("string2", "tea") };
    Object[] complexResourceKeys = new Object[] { new ComplexResourceKey<>(new MyComplexKey().setA("XYZ").setB(111L), new EmptyRecord()), new ComplexResourceKey<>(new MyComplexKey().setA("A2").setB(222L), new EmptyRecord()) };
    return new Object[][] { { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"10002\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", new Object[] { 10001, 99999 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"99999\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", new Object[] { 10001, 10002 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"10002\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", new Object[] { 10001, 10002, 10003 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=apples&string2=oranges\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"string1=coffee&string2=tea\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=apples&string2=oranges\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"string2=oranges&string1=apples\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:apples,string2:oranges)\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"(string1:coffee,string2:tea)\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:apples,string2:oranges)\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"(string2:oranges,string1:apples)\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A1&b=111\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"a=A2&b=222\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", complexResourceKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A2&b=222\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}," + "\"b=222&a=A2\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}}}", complexResourceKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"($params:(),a:A2,b:222)\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}," + "\"($params:(),a:A1,b:111)\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}}}", complexResourceKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"($params:(),a:A2,b:222)\":{\"patch\":{\"$set\":{\"a\":\"someOtherString\"}}}," + "\"($params:(),b:222,a:A2)\":{\"patch\":{\"$set\":{\"a\":\"someString\"}}}}}", complexResourceKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 2 with IntegerDataSchema

use of com.linkedin.data.schema.IntegerDataSchema in project rest.li by linkedin.

the class TestGetArgumentBuilder method testAsyncArguments.

@Test(dataProvider = "asyncArgumentData")
public void testAsyncArguments(List<Parameter<?>> paramList) throws IOException {
    String keyName = "myComplexKeyCollectionId";
    Object keyValue = Integer.valueOf(123);
    DataSchema keySchema = new IntegerDataSchema();
    Key key = new Key(keyName, keyValue.getClass(), keySchema);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, false);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, paramList);
    ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
    RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[] { keyValue, null };
    assertEquals(args, expectedArgs);
    verify(model, descriptor, context, routingResult, request);
}
Also used : IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) DataSchema(com.linkedin.data.schema.DataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 3 with IntegerDataSchema

use of com.linkedin.data.schema.IntegerDataSchema in project rest.li by linkedin.

the class TestGetArgumentBuilder method testFailure.

@Test(dataProvider = "failureData")
public void testFailure(Parameter<?> param, String errorMessage) throws IOException {
    String keyName = "myComplexKeyCollectionId";
    Key key = new Key(keyName, Integer.class, new IntegerDataSchema());
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, true);
    List<Parameter<?>> paramList = Collections.<Parameter<?>>singletonList(param);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, paramList);
    ServerResourceContext context = EasyMock.createMock(ServerResourceContext.class);
    MutablePathKeys mockPathKeys = EasyMock.createMock(MutablePathKeys.class);
    EasyMock.expect(mockPathKeys.get(keyName)).andReturn(null).anyTimes();
    EasyMock.expect(context.getPathKeys()).andReturn(mockPathKeys).anyTimes();
    EasyMock.replay(context, mockPathKeys);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
    RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
    try {
        argumentBuilder.buildArguments(requestData, routingResult);
        fail("Expected RoutingException");
    } catch (RoutingException e) {
        assertEquals(e.getMessage(), errorMessage);
    }
    verify(descriptor, context, routingResult, request);
}
Also used : RoutingException(com.linkedin.restli.server.RoutingException) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) MutablePathKeys(com.linkedin.restli.internal.server.MutablePathKeys) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 4 with IntegerDataSchema

use of com.linkedin.data.schema.IntegerDataSchema in project rest.li by linkedin.

the class TestGetArgumentBuilder method testHeaderArgument.

@Test
public void testHeaderArgument() throws IOException {
    String keyName = "myComplexKeyCollectionId";
    Object keyValue = Integer.valueOf(123);
    DataSchema keySchema = new IntegerDataSchema();
    Key key = new Key(keyName, keyValue.getClass(), keySchema);
    Map<String, String> headers = new HashMap<>();
    String headerString = "An extra string.";
    headers.put("extra", headerString);
    List<Parameter<?>> headerParams = new ArrayList<>();
    headerParams.add(getIntegerParam());
    HeaderParam annotation = createMock(HeaderParam.class);
    expect(annotation.value()).andReturn("extra");
    AnnotationSet annotationSet = createMock(AnnotationSet.class);
    expect(annotationSet.getAll()).andReturn(new Annotation[] {});
    expect(annotationSet.get(HeaderParam.class)).andReturn(annotation);
    replay(annotation, annotationSet);
    Parameter<String> headerParam = new Parameter<>("", String.class, null, false, null, Parameter.ParamType.HEADER, false, annotationSet);
    headerParams.add(headerParam);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, false);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, headerParams);
    ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, headers, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
    RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[] { keyValue, headerString };
    assertEquals(args, expectedArgs);
    verify(model, descriptor, context, routingResult, request, annotation, annotationSet);
}
Also used : HeaderParam(com.linkedin.restli.server.annotations.HeaderParam) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) HashMap(java.util.HashMap) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataSchema(com.linkedin.data.schema.DataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) Parameter(com.linkedin.restli.internal.server.model.Parameter) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 5 with IntegerDataSchema

use of com.linkedin.data.schema.IntegerDataSchema in project rest.li by linkedin.

the class TestUpdateArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    Parameter<?> myComplexKeyParam = new Parameter<>("", MyComplexKey.class, DataTemplateUtil.getSchema(MyComplexKey.class), false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
    List<Parameter<?>> collectionResourceParams = new ArrayList<>();
    collectionResourceParams.add(new Parameter<>("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    collectionResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> simpleResourceParams = new ArrayList<>();
    simpleResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> associationResourceParams = new ArrayList<>();
    associationResourceParams.add(new Parameter<>("myComplexKeyAssociationId", CompoundKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    associationResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> complexResourceKeyParams = new ArrayList<>();
    @SuppressWarnings("rawtypes") Parameter<ComplexResourceKey> complexResourceKeyParam = new Parameter<>("complexKeyTestId", ComplexResourceKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {}));
    complexResourceKeyParams.add(complexResourceKeyParam);
    complexResourceKeyParams.add(myComplexKeyParam);
    return new Object[][] { { collectionResourceParams, new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()), "myComplexKeyCollectionId", 4545 }, { simpleResourceParams, null, null, null }, { associationResourceParams, new Key("myComplexKeyAssociationId", CompoundKey.class, null), "myComplexKeyAssociationId", new CompoundKey().append("string1", "apples").append("string2", "oranges") }, { complexResourceKeyParams, new Key("complexKeyTestId", ComplexResourceKey.class, null), "complexKeyTestId", new ComplexResourceKey<>(new MyComplexKey().setA("keyString").setB(1234L), new EmptyRecord()) } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Parameter(com.linkedin.restli.internal.server.model.Parameter) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Aggregations

IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)8 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)7 CompoundKey (com.linkedin.restli.common.CompoundKey)7 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)7 Key (com.linkedin.restli.server.Key)7 Parameter (com.linkedin.restli.internal.server.model.Parameter)5 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 AnnotationSet (com.linkedin.restli.internal.server.model.AnnotationSet)4 ArrayList (java.util.ArrayList)4 DataProvider (org.testng.annotations.DataProvider)4 RestRequest (com.linkedin.r2.message.rest.RestRequest)3 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)3 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)3 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)3 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)3 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)3 Annotation (java.lang.annotation.Annotation)3 Test (org.testng.annotations.Test)3 DataSchema (com.linkedin.data.schema.DataSchema)2 StringDataSchema (com.linkedin.data.schema.StringDataSchema)1