Search in sources :

Example 36 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingSubResourceCollectionBatch.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingSubResourceCollectionBatch")
public void testRoutingSubResourceCollectionBatch(String uri, ProtocolVersion version, String httpMethod, String restliMethod, ResourceMethod method, String methodName, Set<Long> keys) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, RepliesCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    checkResult(uri, version, httpMethod, restliMethod, method, RepliesCollectionResource.class, methodName, true);
    checkBatchKeys(uri, version, httpMethod, keys);
}
Also used : RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiConfig(com.linkedin.restli.server.RestLiConfig) Test(org.testng.annotations.Test)

Example 37 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.

the class TestRestLiRouting method testActionNestedSimpleRouting.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionNestedSimpleRouting")
public void testActionNestedSimpleRouting(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    RestRequest request = createRequest(uri, "POST", version);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    ResourceMethodDescriptor method = _router.process(context);
    assertNotNull(method);
    assertEquals(method.getActionName(), "new_status_from_location");
    assertEquals(method.getType(), ResourceMethod.ACTION);
    assertEquals(method.getMethod().getParameterTypes(), new Class<?>[] { String.class });
    assertEquals(context.getPathKeys().get("statusID"), Long.valueOf(1));
}
Also used : RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test)

Example 38 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.

the class RestLiResourceModelExporter method generateIDLFiles.

private GeneratorResult generateIDLFiles(String apiName, String outdir, Map<String, ResourceModel> rootResourceMap, DocsProvider docsProvider) throws IOException {
    Result result = new Result();
    final File outdirFile = new File(outdir);
    if (!outdirFile.exists()) {
        if (!outdirFile.mkdirs()) {
            throw new RuntimeException("Output directory '" + outdir + "' could not be created!");
        }
    }
    if (!outdirFile.isDirectory()) {
        throw new RuntimeException("Output directory '" + outdir + "' is not a directory");
    }
    if (!outdirFile.canRead() || !outdirFile.canWrite()) {
        throw new RuntimeException("Output directory '" + outdir + "' must be writeable");
    }
    final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);
    final List<ResourceSchema> rootResourceNodes = new ArrayList<>();
    for (Entry<String, ResourceModel> entry : rootResourceMap.entrySet()) {
        final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
        rootResourceNodes.add(rootResourceNode);
    }
    for (ResourceSchema rootResourceNode : rootResourceNodes) {
        String fileName = rootResourceNode.getName();
        if (rootResourceNode.getNamespace() != null) {
            final String namespace = rootResourceNode.getNamespace();
            fileName = namespace + "." + fileName;
        }
        if (apiName != null && !apiName.isEmpty()) {
            fileName = apiName + "-" + fileName;
        }
        File writtenFile = writeIDLFile(outdirFile, fileName, rootResourceNode);
        result.addModifiedFile(writtenFile);
        result.addTargetFile(writtenFile);
    }
    return result;
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) ResourceModelEncoder(com.linkedin.restli.internal.server.model.ResourceModelEncoder) ArrayList(java.util.ArrayList) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) File(java.io.File) GeneratorResult(com.linkedin.pegasus.generator.GeneratorResult)

Example 39 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.

the class RestLiSnapshotExporter method generateSnapshotFiles.

private GeneratorResult generateSnapshotFiles(String apiName, String outdir, Map<String, ResourceModel> rootResourceMap, DocsProvider docsProvider) throws IOException {
    SnapshotResult result = new SnapshotResult();
    final File outdirFile = new File(outdir);
    if (!outdirFile.exists()) {
        if (!outdirFile.mkdirs()) {
            throw new RuntimeException("Output directory '" + outdir + "' could not be created!");
        }
    }
    if (!outdirFile.isDirectory()) {
        throw new RuntimeException("Output directory '" + outdir + "' is not a directory");
    }
    if (!outdirFile.canRead() || !outdirFile.canWrite()) {
        throw new RuntimeException("Output directory '" + outdir + "' must be writeable");
    }
    final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);
    final List<ResourceSchema> rootResourceNodes = new ArrayList<>();
    for (Map.Entry<String, ResourceModel> entry : rootResourceMap.entrySet()) {
        final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
        rootResourceNodes.add(rootResourceNode);
    }
    for (ResourceSchema rootResourceNode : rootResourceNodes) {
        String fileName = rootResourceNode.getName();
        if (rootResourceNode.hasNamespace()) {
            final String namespace = rootResourceNode.getNamespace();
            fileName = namespace + "." + fileName;
        }
        if (apiName != null && !apiName.isEmpty()) {
            fileName = apiName + "-" + fileName;
        }
        File writtenFile = writeSnapshotFile(outdirFile, fileName, rootResourceNode);
        result.addModifiedFile(writtenFile);
        result.addTargetFile(writtenFile);
    }
    return result;
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) ResourceModelEncoder(com.linkedin.restli.internal.server.model.ResourceModelEncoder) ArrayList(java.util.ArrayList) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.

the class ResourceSchemaCollection method loadOrCreateResourceSchema.

/**
 * For each given {@link ResourceModel}, the classpath is checked for a .restspec.json
 * matching the name of the {@link ResourceModel},  if found it is loaded.  If a .restspec.json file
 * is not found, one is created {@link ResourceSchemaCollection} from specified root {@link ResourceModel}.
 * All resources will be recursively traversed to discover subresources.
 * Root resources not specified are excluded.
 *
 * @param rootResources root resources in ResourceModel type
 * @return constructed ResourceSchemaCollection
 */
public static ResourceSchemaCollection loadOrCreateResourceSchema(Map<String, ResourceModel> rootResources) {
    final ResourceModelEncoder encoder = new ResourceModelEncoder(new NullDocsProvider());
    final Map<String, ResourceSchema> schemaMap = new TreeMap<>();
    for (ResourceModel resource : rootResources.values()) {
        schemaMap.put(resource.getName(), encoder.loadOrBuildResourceSchema(resource));
    }
    return new ResourceSchemaCollection(schemaMap, rootResources);
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) ResourceModelEncoder(com.linkedin.restli.internal.server.model.ResourceModelEncoder) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) TreeMap(java.util.TreeMap) NullDocsProvider(com.linkedin.restli.internal.server.model.ResourceModelEncoder.NullDocsProvider)

Aggregations

ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)223 Test (org.testng.annotations.Test)190 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)161 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)139 AfterTest (org.testng.annotations.AfterTest)114 BeforeTest (org.testng.annotations.BeforeTest)114 ByteString (com.linkedin.data.ByteString)50 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)50 CustomString (com.linkedin.restli.server.custom.types.CustomString)43 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)40 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)37 RestRequest (com.linkedin.r2.message.rest.RestRequest)36 Callback (com.linkedin.common.callback.Callback)34 RestLiConfig (com.linkedin.restli.server.RestLiConfig)34 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)32 RequestContext (com.linkedin.r2.message.RequestContext)29 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)28 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)28 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)28 TaskStatusCollectionResource (com.linkedin.restli.server.twitter.TaskStatusCollectionResource)28