Search in sources :

Example 6 with StringDataSchema

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

the class TestResourceCompatibilityChecker method bindSchemaResolvers.

private void bindSchemaResolvers() {
    StringBuilder errors = new StringBuilder();
    Name toneName = new Name("com.linkedin.greetings.api.Tone");
    EnumDataSchema tone = new EnumDataSchema(toneName);
    List<String> symbols = new ArrayList<String>();
    symbols.add("FRIENDLY");
    symbols.add("SINCERE");
    symbols.add("INSULTING");
    tone.setSymbols(symbols, errors);
    Name greetingName = new Name("com.linkedin.greetings.api.Greeting");
    RecordDataSchema prevGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> oldFields = new ArrayList<RecordDataSchema.Field>();
    RecordDataSchema.Field id = new RecordDataSchema.Field(new LongDataSchema());
    id.setName("id", errors);
    oldFields.add(id);
    RecordDataSchema.Field message = new RecordDataSchema.Field(new StringDataSchema());
    message.setName("message", errors);
    oldFields.add(message);
    RecordDataSchema.Field toneField = new RecordDataSchema.Field(tone);
    toneField.setName("tone", errors);
    toneField.setOptional(true);
    oldFields.add(toneField);
    prevGreeting.setFields(oldFields, errors);
    prevSchemaResolver.bindNameToSchema(toneName, tone, null);
    prevSchemaResolver.bindNameToSchema(greetingName, prevGreeting, null);
    // compat greeting added a new optional field "newField"
    RecordDataSchema compatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> compatFields = new ArrayList<RecordDataSchema.Field>();
    compatFields.add(id);
    compatFields.add(message);
    compatFields.add(toneField);
    RecordDataSchema.Field newCompatField = new RecordDataSchema.Field(new StringDataSchema());
    newCompatField.setName("newField", errors);
    newCompatField.setOptional(true);
    compatFields.add(newCompatField);
    compatGreeting.setFields(compatFields, errors);
    compatSchemaResolver.bindNameToSchema(toneName, tone, null);
    compatSchemaResolver.bindNameToSchema(greetingName, compatGreeting, null);
    // incompat greeting has removed non-optional field "message",
    // has changed the type of "id" to string,
    // and added a new non-optional field "newField"
    RecordDataSchema incompatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
    List<RecordDataSchema.Field> incompatFields = new ArrayList<RecordDataSchema.Field>();
    RecordDataSchema.Field incompatId = new RecordDataSchema.Field(new StringDataSchema());
    incompatId.setName("id", errors);
    oldFields.add(incompatId);
    incompatFields.add(incompatId);
    incompatFields.add(toneField);
    RecordDataSchema.Field newIncompatField = new RecordDataSchema.Field(new StringDataSchema());
    newIncompatField.setName("newField", errors);
    incompatFields.add(newIncompatField);
    incompatGreeting.setFields(incompatFields, errors);
    incompatSchemaResolver.bindNameToSchema(toneName, tone, null);
    incompatSchemaResolver.bindNameToSchema(greetingName, incompatGreeting, null);
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ArrayList(java.util.ArrayList) LongDataSchema(com.linkedin.data.schema.LongDataSchema) Name(com.linkedin.data.schema.Name)

Example 7 with StringDataSchema

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

the class TestCollectionArgumentBuilder method testProjectionParams.

@Test
public void testProjectionParams() {
    List<Parameter<?>> finderWithProjectionParams = new ArrayList<Parameter<?>>();
    finderWithProjectionParams.add(new Parameter<String>("key", String.class, new StringDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<PagingContext>("", PagingContext.class, null, false, new PagingContext(0, 10), Parameter.ParamType.PAGING_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.METADATA_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.PAGING_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    Map<String, String> finderWithProjectionContextParams = new HashMap<String, String>();
    finderWithProjectionContextParams.put("start", "100");
    finderWithProjectionContextParams.put("count", "15");
    finderWithProjectionContextParams.put("key", "keyString");
    Map<String, Integer> projectionMap = new HashMap<String, Integer>();
    projectionMap.put("a", 1);
    Map<String, Integer> metadataMap = new HashMap<String, Integer>();
    metadataMap.put("intField", 1);
    metadataMap.put("booleanField", 1);
    Map<String, Integer> pagingMap = new HashMap<String, Integer>();
    pagingMap.put("total", 1);
    MaskTree projectionMask = new MaskTree(new DataMap(projectionMap));
    MaskTree metadataMask = new MaskTree(new DataMap(metadataMap));
    MaskTree pagingMask = new MaskTree(new DataMap(pagingMap));
    Object[] expectedArgs = new Object[] { "keyString", new PagingContext(100, 15), projectionMask, metadataMask, pagingMask };
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, finderWithProjectionParams);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(finderWithProjectionContextParams, projectionMask, metadataMask, pagingMask, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args, expectedArgs);
    verify(descriptor, context, routingResult, request);
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) HashMap(java.util.HashMap) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataMap(com.linkedin.data.DataMap) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringDataSchema(com.linkedin.data.schema.StringDataSchema) RestRequest(com.linkedin.r2.message.rest.RestRequest) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PagingContext(com.linkedin.restli.server.PagingContext) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 8 with StringDataSchema

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

the class TestCollectionArgumentBuilder method getFinderParams.

private List<Parameter<?>> getFinderParams() {
    List<Parameter<?>> finderParams = new ArrayList<Parameter<?>>();
    finderParams.add(getPagingContextParam());
    Parameter<Integer> requiredIntParam = new Parameter<Integer>("required", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
    finderParams.add(requiredIntParam);
    Parameter<String> optionalStringParam = new Parameter<String>("optional", String.class, new StringDataSchema(), true, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
    finderParams.add(optionalStringParam);
    return finderParams;
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) ArrayList(java.util.ArrayList) Parameter(com.linkedin.restli.internal.server.model.Parameter) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation)

Example 9 with StringDataSchema

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

the class TestBatchCreateResponseBuilder method createKVResultBuilderTestData.

@DataProvider(name = "createKVResultBuilderTestData")
public Object[][] createKVResultBuilderTestData() {
    Map<String, AlternativeKey<?, ?>> alternativeKeyMap = new HashMap<String, AlternativeKey<?, ?>>();
    alternativeKeyMap.put("alt", new AlternativeKey<String, Long>(new TestKeyCoercer(), String.class, new StringDataSchema()));
    Foo foo1 = new Foo();
    foo1.setStringField("foo1");
    Foo foo2 = new Foo();
    foo2.setStringField("foo2");
    List<CreateIdEntityStatus<Long, Foo>> expectedResponses = new ArrayList<CreateIdEntityStatus<Long, Foo>>(2);
    expectedResponses.add(new CreateIdEntityStatus<Long, Foo>(201, 1L, foo1, null, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()));
    expectedResponses.add(new CreateIdEntityStatus<Long, Foo>(201, 2L, foo2, null, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()));
    List<CreateIdEntityStatus<String, Foo>> expectedAltResponses = new ArrayList<CreateIdEntityStatus<String, Foo>>(2);
    expectedAltResponses.add(new CreateIdEntityStatus<String, Foo>(201, "Alt1", foo1, null, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()));
    expectedAltResponses.add(new CreateIdEntityStatus<String, Foo>(201, "Alt2", foo2, null, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()));
    return new Object[][] { { null, null, expectedResponses }, { "alt", alternativeKeyMap, expectedAltResponses } };
}
Also used : CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) HashMap(java.util.HashMap) Foo(com.linkedin.pegasus.generator.examples.Foo) ArrayList(java.util.ArrayList) StringDataSchema(com.linkedin.data.schema.StringDataSchema) AlternativeKey(com.linkedin.restli.server.AlternativeKey) DataProvider(org.testng.annotations.DataProvider)

Example 10 with StringDataSchema

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

the class TestCreateResponseBuilder method testDataProvider.

@DataProvider(name = "testData")
public Object[][] testDataProvider() {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    Map<String, AlternativeKey<?, ?>> alternativeKeyMap = new HashMap<String, AlternativeKey<?, ?>>();
    alternativeKeyMap.put("alt", new AlternativeKey<String, CompoundKey>(new TestKeyCoercer(), String.class, new StringDataSchema()));
    return new Object[][] { { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), compoundKey, "/foo/a=a&b=1", "a=a&b=1", null, null }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), compoundKey, "/foo/(a:a,b:1)", "(a:a,b:1)", null, null }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "aaxb1", "/foo/aaxb1?altkey=alt", "aaxb1", "alt", alternativeKeyMap }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "aaxb1", "/foo/aaxb1?altkey=alt", "aaxb1", "alt", alternativeKeyMap } };
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) AlternativeKey(com.linkedin.restli.server.AlternativeKey) DataProvider(org.testng.annotations.DataProvider)

Aggregations

StringDataSchema (com.linkedin.data.schema.StringDataSchema)10 HashMap (java.util.HashMap)7 DataProvider (org.testng.annotations.DataProvider)6 CompoundKey (com.linkedin.restli.common.CompoundKey)5 ArrayList (java.util.ArrayList)5 AlternativeKey (com.linkedin.restli.server.AlternativeKey)4 Foo (com.linkedin.pegasus.generator.examples.Foo)3 AnnotationSet (com.linkedin.restli.internal.server.model.AnnotationSet)3 Parameter (com.linkedin.restli.internal.server.model.Parameter)3 DataMap (com.linkedin.data.DataMap)2 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)2 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)2 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)2 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)2 Key (com.linkedin.restli.server.Key)2 PagingContext (com.linkedin.restli.server.PagingContext)2 ResourceContext (com.linkedin.restli.server.ResourceContext)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2