Search in sources :

Example 26 with Api

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

the class ApiConfigValidatorTest method testValidateMethods_ignoredMethod.

@Test
public void testValidateMethods_ignoredMethod() throws Exception {
    final class Bean {
    }
    @Api
    final class Endpoint {

        @ApiMethod(ignored = AnnotationBoolean.TRUE)
        public void thisShouldBeIgnored(Bean resource1, Bean resource2) {
        }
    }
    ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Endpoint.class);
    // If this passes validation, then no error will be thrown. Otherwise, the validator will
    // complain that the method has two resources.
    validator.validate(config);
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 27 with Api

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

the class ApiConfigValidatorTest method testApiMethodConfigWithApiMethodNameContainingContinuousDots.

@Test
public void testApiMethodConfigWithApiMethodNameContainingContinuousDots() throws Exception {
    @Api(name = "testApi", version = "v1", resource = "bar")
    final class Test {

        @ApiMethod(name = "TestApi..testMethod")
        public void test() {
        }
    }
    ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Test.class);
    try {
        validator.validate(config);
        fail("Expected InvalidMethodNameException.");
    } catch (InvalidMethodNameException expected) {
    }
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 28 with Api

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

the class ApiConfigValidatorTest method testApiWideConfigWithInvalidApiName.

@Test
public void testApiWideConfigWithInvalidApiName() throws Exception {
    @Api(name = "TestApi", version = "v1", resource = "bar")
    final class Test {
    }
    ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Test.class);
    try {
        validator.validate(config);
        fail("Expected InvalidApiNameException.");
    } catch (InvalidApiNameException expected) {
    }
}
Also used : ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 29 with Api

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

the class ApiConfigAnnotationReaderTest method testMethodDescription.

@Test
public void testMethodDescription() throws Exception {
    @Api
    final class MethodDescriptionEndpoint {

        public void noAnnotation() {
        }

        @ApiMethod
        public void noDescription() {
        }

        @ApiMethod(description = "description")
        public void withDescription() {
        }
    }
    ApiConfig config = createConfig(MethodDescriptionEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, MethodDescriptionEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noAnnotation")));
    assertNull(method1.getDescription());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("noDescription")));
    assertNull(method2.getDescription());
    ApiMethodConfig method3 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(MethodDescriptionEndpoint.class.getMethod("withDescription")));
    assertEquals("description", method3.getDescription());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 30 with Api

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

the class AnnotationApiConfigGeneratorTest method testCanonicalName.

@Test
public void testCanonicalName() throws Exception {
    @Api(name = "myapi", canonicalName = "My API")
    class CanonicalApi {
    }
    String apiConfigSource = g.generateConfig(CanonicalApi.class).get("myapi-v1.api");
    ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class);
    assertEquals("myapi", root.path("name").asText());
    assertEquals("My API", root.path("canonicalName").asText());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Aggregations

Api (com.google.api.server.spi.config.Api)56 Test (org.junit.Test)55 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)45 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)29 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)27 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 Named (javax.inject.Named)15 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)8 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)7 DefaultValueSerializer (com.google.api.server.spi.testing.DefaultValueSerializer)4 Collection (java.util.Collection)4 Foo (com.google.api.server.spi.testing.Foo)3 List (java.util.List)3 TypeLoader (com.google.api.server.spi.TypeLoader)2 ApiFrontendLimits (com.google.api.server.spi.config.ApiFrontendLimits)2 Named (com.google.api.server.spi.config.Named)2 ApiKey (com.google.api.server.spi.config.model.ApiKey)2 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)2 Date (java.util.Date)2