use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestCollectionResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
@SuppressWarnings("unchecked")
public <D extends RestLiResponseData<? extends CollectionResponseEnvelope>> void testProjectionInBuildRestliResponseData() throws URISyntaxException {
for (Map.Entry<ResourceMethod, CollectionResponseBuilder<?>> entry : BUILDERS.entrySet()) {
ResourceMethod resourceMethod = entry.getKey();
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = getMockResourceContext(maskTree, null, null, ProjectionMode.AUTOMATIC, ProjectionMode.AUTOMATIC);
RoutingResult routingResult = new RoutingResult(mockContext, getMockResourceMethodDescriptor());
List<RecordTemplate> values = new ArrayList<>();
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
values.add(value);
CollectionResponseBuilder<D> responseBuilder = (CollectionResponseBuilder<D>) entry.getValue();
D responseData = responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, values, Collections.emptyMap(), Collections.emptyList());
RecordTemplate record = responseData.getResponseEnvelope().getCollectionResponse().get(0);
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
}
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestRestLiResponseData method provideAllBaseObjects.
@DataProvider(name = "baseClassOperations")
public Object[][] provideAllBaseObjects() {
RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR);
ResourceMethod[] methods = ResourceMethod.class.getEnumConstants();
Object[][] sampleResponseData = new Object[methods.length * 2][1];
for (int i = 0; i < methods.length; i++) {
RestLiResponseData<?> successResponseData = buildResponseData(methods[i], HttpStatus.S_200_OK);
RestLiResponseData<?> errorResponseData = ErrorResponseBuilder.buildErrorResponseData(methods[i], exception, Collections.emptyMap(), Collections.emptyList());
sampleResponseData[i * 2] = new Object[] { successResponseData };
sampleResponseData[i * 2 + 1] = new Object[] { errorResponseData };
}
return sampleResponseData;
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResult.
private RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders, Set<String> customTypes) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(resourceMethod, method, InterfaceType.SYNC);
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, customTypes, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestRequestBuilderSpecGenerator method testSimpleResource.
@Test
public void testSimpleResource() throws Exception {
String idl = moduleDir + FS + IDLS_DIR + FS + "testSimple.restspec.json";
Set<BuilderSpec> builderSpecs = generateBuilderSpec(new String[] { idl });
Assert.assertNotNull(builderSpecs);
Assert.assertTrue(builderSpecs.size() == 6);
Map<String, String> methodMap = new HashMap<>();
methodMap.put("get", "Gets the greeting.");
methodMap.put("delete", "Deletes the greeting.");
methodMap.put("update", "Updates the greeting.");
for (BuilderSpec spec : builderSpecs) {
Assert.assertTrue(spec instanceof RootBuilderSpec || spec instanceof RestMethodBuilderSpec);
if (spec instanceof RootBuilderSpec) {
Assert.assertTrue(spec instanceof SimpleRootBuilderSpec);
SimpleRootBuilderSpec simpleSpec = (SimpleRootBuilderSpec) spec;
if (simpleSpec.getResourcePath().indexOf('/') >= 0) {
Assert.assertEquals(simpleSpec.getSourceIdlName(), idl);
Assert.assertEquals(simpleSpec.getResourcePath(), "testSimple/testSimpleSub");
Assert.assertNotNull(simpleSpec.getRestMethods());
Assert.assertTrue(simpleSpec.getRestMethods().size() == 1);
Assert.assertEquals("get", simpleSpec.getRestMethods().get(0).getName());
Assert.assertTrue(simpleSpec.getResourceActions().isEmpty());
Assert.assertTrue(simpleSpec.getSubresources().isEmpty());
} else {
Assert.assertTrue(simpleSpec.getResourceActions().isEmpty());
Assert.assertTrue(simpleSpec.getSubresources().size() == 1);
Assert.assertEquals(simpleSpec.getSourceIdlName(), idl);
Assert.assertEquals(simpleSpec.getResourcePath(), "testSimple");
Assert.assertNotNull(simpleSpec.getRestMethods());
Assert.assertTrue(simpleSpec.getRestMethods().size() == 3);
List<RootBuilderMethodSpec> restMethods = simpleSpec.getRestMethods();
for (RootBuilderMethodSpec method : restMethods) {
Assert.assertTrue(method.getReturn() instanceof RestMethodBuilderSpec);
Assert.assertEquals(method.getReturn().getRootBuilderMethod(), method);
Assert.assertTrue(methodMap.containsKey(method.getName()));
Assert.assertEquals(methodMap.get(method.getName()), method.getDoc());
}
}
} else if (spec instanceof RestMethodBuilderSpec) {
RestMethodBuilderSpec builderSpec = (RestMethodBuilderSpec) spec;
ResourceMethod method = builderSpec.getResourceMethod();
Assert.assertTrue(methodMap.containsKey(method.toString()));
Assert.assertFalse(builderSpec.hasBindingMethods());
}
}
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestRequestBuilderSpecGenerator method generateBuilderSpec.
private Set<BuilderSpec> generateBuilderSpec(String[] sources) {
final DataSchemaParser schemaParser = new DataSchemaParser.Builder(RESOLVER_DIR).build();
final TemplateSpecGenerator specGenerator = new TemplateSpecGenerator(schemaParser.getSchemaResolver());
final RestSpecParser parser = new RestSpecParser();
final Map<ResourceMethod, String> builderBaseMap = new HashMap<>();
builderBaseMap.put(ResourceMethod.GET, "GetRequestBuilder");
builderBaseMap.put(ResourceMethod.DELETE, "DeleteRequestBuilder");
builderBaseMap.put(ResourceMethod.UPDATE, "UpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.CREATE, "CreateIdRequestBuilder");
builderBaseMap.put(ResourceMethod.PARTIAL_UPDATE, "PartialUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.GET_ALL, "GetAllRequestBuilder");
builderBaseMap.put(ResourceMethod.OPTIONS, "OptionsRequestBuilder");
builderBaseMap.put(ResourceMethod.ACTION, "ActionRequestBuilder");
builderBaseMap.put(ResourceMethod.FINDER, "FinderRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_GET, "BatchGetRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_UPDATE, "BatchUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_PARTIAL_UPDATE, "BatchPartialUpdateRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_DELETE, "BatchDeleteRequestBuilder");
builderBaseMap.put(ResourceMethod.BATCH_CREATE, "BatchCreateIdRequestBuilder");
final RequestBuilderSpecGenerator builderSpecGenerator = new RequestBuilderSpecGenerator(schemaParser.getSchemaResolver(), specGenerator, RestliVersion.RESTLI_2_0_0, builderBaseMap);
// parse idl to ResourceSchemas
final RestSpecParser.ParseResult parseResult = parser.parseSources(sources);
// generate Builder specs from ResourceSchema
for (CodeUtil.Pair<ResourceSchema, File> pair : parseResult.getSchemaAndFiles()) {
builderSpecGenerator.generate(pair.first, pair.second);
}
return builderSpecGenerator.getBuilderSpec();
}
Aggregations