Search in sources :

Example 11 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testSimpleOverloadEndpoint.

@Test
public void testSimpleOverloadEndpoint() throws Exception {
    ApiConfig config = createConfig(SimpleOverloadEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, SimpleOverloadEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleOverloadEndpoint.class.getMethod("foo", Integer.class)));
    assertEquals("api.foos.fn", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(SimpleOverloadEndpoint.class.getSuperclass().getMethod("foo", String.class)));
    assertEquals("api.foos.base", method2.getName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) SimpleOverloadEndpoint(com.google.api.server.spi.testing.SimpleOverloadEndpoint) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 12 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testEndpointNoApiAnnotation.

@Test
public void testEndpointNoApiAnnotation() throws Exception {
    ApiConfig config = createConfig(Object.class);
    try {
        annotationReader.loadEndpointClass(serviceContext, Object.class, config);
        fail("No @Api annotation should've caused reader to fail.");
    } catch (ApiConfigException expected) {
        assertEquals("class java.lang.Object has no @Api annotation.", expected.getMessage());
    }
}
Also used : ApiConfigException(com.google.api.server.spi.config.ApiConfigException) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 13 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testCollectionCovarianceEndpoint.

@Test
public void testCollectionCovarianceEndpoint() throws Exception {
    ApiConfig config = createConfig(CollectionCovarianceEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, CollectionCovarianceEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(CollectionCovarianceEndpoint.class.getMethod("foo", List.class)));
    assertEquals("api.foos.fn", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(CollectionCovarianceEndpoint.class.getSuperclass().getMethod("foo", Collection.class)));
    assertEquals("api.foos.base", method2.getName());
}
Also used : CollectionCovarianceEndpoint(com.google.api.server.spi.testing.CollectionCovarianceEndpoint) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 14 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testEndpointWithInheritance.

@Test
public void testEndpointWithInheritance() throws Exception {
    ApiConfig config = createConfig(Endpoint3.class);
    annotationReader.loadEndpointClass(serviceContext, Endpoint3.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Endpoint3.class, config.getApiClassConfig().getMethods());
    validateEndpoint1(config, Endpoint3.class);
    String[] defaultScopes = { "ss0", "ss1 ss2" };
    String[] defaultAudiences = { "aa0", "aa1" };
    String[] defaultClientIds = { "cc0", "cc1" };
    ApiMethodConfig getBar = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Endpoint3.class.getMethod("getBar", String.class)));
    validateMethod(getBar, "Endpoint3.getBar", "bar/{id}", ApiMethod.HttpMethod.GET, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, getBar.getParameterConfigs().size());
    validateParameter(getBar.getParameterConfigs().get(0), "id", false, null, String.class);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) PassPeerAuthenticator(com.google.api.server.spi.testing.PassPeerAuthenticator) PassAuthenticator(com.google.api.server.spi.testing.PassAuthenticator) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 15 with ApiConfig

use of com.google.api.server.spi.config.model.ApiConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testDeepGenericHierarchyFailEndpoint.

@Test
public void testDeepGenericHierarchyFailEndpoint() throws Exception {
    ApiConfig config = createConfig(DeepGenericHierarchyFailEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, DeepGenericHierarchyFailEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(DeepGenericHierarchyFailEndpoint.class, DeepGenericHierarchyFailEndpoint.class.getMethod("foo", String.class, Integer.class, Collection.class)));
    assertEquals("DeepGenericHierarchyFailEndpoint.foo", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(DeepGenericHierarchyFailEndpoint.class, DeepGenericHierarchyFailEndpoint.class.getSuperclass().getSuperclass().getSuperclass().getMethod("foo", Object.class, Object.class, Object.class)));
    assertEquals("Endpoint3.foo", method2.getName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) DeepGenericHierarchyFailEndpoint(com.google.api.server.spi.testing.DeepGenericHierarchyFailEndpoint) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Aggregations

ApiConfig (com.google.api.server.spi.config.model.ApiConfig)91 Test (org.junit.Test)72 Api (com.google.api.server.spi.config.Api)29 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)26 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)20 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)18 ApiKey (com.google.api.server.spi.config.model.ApiKey)9 Swagger (io.swagger.models.Swagger)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 TypeLoader (com.google.api.server.spi.TypeLoader)5 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)4 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)4 ServiceContext (com.google.api.server.spi.ServiceContext)3 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ApiClass (com.google.api.server.spi.config.ApiClass)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 ApiReference (com.google.api.server.spi.config.ApiReference)2 Named (com.google.api.server.spi.config.Named)2 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)2