Search in sources :

Example 1 with ResourceType

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

the class TestResourceSchemaCollection method testRootWithResourceModel.

@Test
public void testRootWithResourceModel() {
    final Map<String, ResourceType> expectedTypes = new HashMap<String, ResourceType>();
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.actions", ResourceType.ACTIONS);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.annotatedComplexKeys", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.autoValidationDemos", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.autoValidationWithProjection", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.compression", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.customTypes", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.customTypes2", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.customTypes3", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.chainedTyperefs", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.createGreeting", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.projectMessage", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.validationCreateAndGet", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.customMetadataProjections", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.customTypes2.customTypes4", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.typerefKeys", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.cookie", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.withContext", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.exceptions", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.exceptions2", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.exceptions3", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetings", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.nullGreeting", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsAuth", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsCallback", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsPromise", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsPromiseCtx", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsTask", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greetingsold", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.streamingGreetings", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.mixed", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.pagingMetadataProjections", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.stringKeys", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.stringKeys.stringKeysSub", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.complexArray", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.complexKeys", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.complexKeys.complexKeysSub", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.complexByteKeys", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.associations", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.associations.associationsSub", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.finders", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greeting", ResourceType.SIMPLE);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greeting.subgreetings", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.typerefPrimitiveLongAssociationKeyResource", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.typerefCustomDoubleAssociationKeyResource", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.greeting.subgreetings.subsubgreeting", ResourceType.SIMPLE);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.validationDemos", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.groups.client.groupMemberships", ResourceType.ASSOCIATION);
    expectedTypes.put("com.linkedin.restli.examples.groups.client.groupMembershipsComplex", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.groups.client.groups", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.groups.client.groups.contacts", ResourceType.COLLECTION);
    expectedTypes.put("noNamespace", ResourceType.COLLECTION);
    expectedTypes.put("noNamespace.noNamespaceSub", ResourceType.COLLECTION);
    expectedTypes.put("noNamespace.noNamespaceSub.subSub", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.noNamespace.noNamespace", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.typeref.client.typeref", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.manualProjections", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.scala.client.scalaGreetings", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.greetings.client.asyncErrors", ResourceType.ACTIONS);
    for (Map.Entry<String, ResourceSchema> entry : _schemas.getResources().entrySet()) {
        final ResourceSchema schema = entry.getValue();
        final ResourceType actualType;
        if (schema.hasCollection()) {
            actualType = ResourceType.COLLECTION;
        } else if (schema.hasAssociation()) {
            actualType = ResourceType.ASSOCIATION;
        } else if (schema.hasSimple()) {
            actualType = ResourceType.SIMPLE;
        } else {
            Assert.assertTrue(schema.hasActionsSet());
            actualType = ResourceType.ACTIONS;
        }
        final String schemaFullName = getResourceSchemaFullName(schema, entry.getKey());
        final ResourceType expectedType = expectedTypes.get(schemaFullName);
        Assert.assertNotNull(expectedType, "Resource type for " + schemaFullName);
        Assert.assertSame(actualType, expectedType, schemaFullName);
    }
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) HashMap(java.util.HashMap) ResourceType(com.linkedin.restli.internal.server.model.ResourceType) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

ResourceType (com.linkedin.restli.internal.server.model.ResourceType)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1