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);
}
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);
}
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;
}
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 } };
}
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 } };
}
Aggregations