com.google.api.server.spi.config.Api Java Examples
The following examples show how to use
com.google.api.server.spi.config.Api.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testGenericCollectionRequest() throws Exception { @Api abstract class GenericCollection<T> { @SuppressWarnings("unused") public void foo(@Named("collection") Collection<T> t) {} } // TODO: remove with JDK8, dummy to force inclusion of GenericArray to InnerClass attribute // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2210448 GenericCollection<Long> dummy = new GenericCollection<Long>() {}; class Int64Collection extends GenericCollection<Long> {} String apiConfigSource = g.generateConfig(Int64Collection.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode methodNode = root.path("methods").path("myapi.int64Collection.foo"); assertFalse(methodNode.isMissingNode()); verifyMethodRequestParameter(methodNode.get("request"), "collection", "int64", true, true); }
Example #2
Source File: ApiConfigValidatorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testNonuniqueRestSignatures_multiClass() throws Exception { @Api class Foo { @ApiMethod(path = "path") public void foo() {} } ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Foo.class); @Api class Bar { @ApiMethod(path = "path") public void bar() {} } ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Bar.class); try { validator.validate(Lists.newArrayList(config1, config2)); fail(); } catch (DuplicateRestPathException expected) { } }
Example #3
Source File: ApiConfigValidatorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testInconsistentApiWideConfig() throws Exception { @Api(name = "testApi", version = "v1", resource = "foo") final class Test1 {} ApiConfig config1 = configLoader.loadConfiguration(ServiceContext.create(), Test1.class); @Api(name = "testApi", version = "v1", resource = "bar") final class Test2 {} ApiConfig config2 = configLoader.loadConfiguration(ServiceContext.create(), Test2.class); try { validator.validate(Lists.newArrayList(config1, config2)); fail("Expected InconsistentApiConfigurationException."); } catch (InconsistentApiConfigurationException expected) { } }
Example #4
Source File: ApiConfigValidatorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testApiMethodConfigWithApiMethodNameContainingStartingDot() throws Exception { @Api(name = "testApi", version = "v1", resource = "bar") final class Test { @ApiMethod(name = ".Api.TestMethod") public void test() { } } ApiConfig config = configLoader.loadConfiguration(ServiceContext.create(), Test.class); try { validator.validate(config); fail("Expected InvalidMethodNameException."); } catch (InvalidMethodNameException expected) { } }
Example #5
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testInconsistentApiWideConfig() throws Exception { @Api(scopes = { "foo" }) @ApiClass(scopes = { "scopes" }) final class Test1 {} @Api(scopes = { "bar" }) @ApiClass(scopes = { "scopes" }) final class Test2 {} try { g.generateConfig(Test1.class, Test2.class); fail(); } catch (InconsistentApiConfigurationException e) { // Expected exception. } }
Example #6
Source File: ApiConfigValidatorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: ApiConfigValidatorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@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) { } }
Example #8
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testWildcardParameterTypes() throws Exception { @Api final class WildcardEndpoint { @SuppressWarnings("unused") public void foo(Map<String, ? extends Integer> map) {} } try { ApiConfig config = createConfig(WildcardEndpoint.class); annotationReader.loadEndpointMethods(serviceContext, WildcardEndpoint.class, config.getApiClassConfig().getMethods()); fail("Config generation for service class with wildcard parameter type should have failed"); } catch (IllegalArgumentException e) { // expected } }
Example #9
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testResourceAndCollection() throws Exception { @Api class ResourceAndCollection { @SuppressWarnings("unused") public void foo(Bean resource, @Named("authors") List<String> authors) {} } String apiConfigSource = g.generateConfig(ResourceAndCollection.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode methodNode = root.path("methods").path("myapi.resourceAndCollection.foo"); assertFalse(methodNode.isMissingNode()); verifyMethodRequestParameter(methodNode.get("request"), "authors", "string", true, true); assertEquals(1, methodNode.path("request").path("parameters").size()); verifyMethodRequestRef(root, ResourceAndCollection.class.getName() + ".foo", "Bean"); }
Example #10
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSerializedParameter() throws Exception { @Api final class Test { @SuppressWarnings("unused") public void method(@Named("serialized") TestBean tb) {} } ApiConfig config = createConfig(Test.class); annotationReader.loadEndpointClass(serviceContext, Test.class, config); annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods()); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(Test.class.getMethod( "method", TestBean.class))); validateMethod(methodConfig, "Test.method", "method/{serialized}", ApiMethod.HttpMethod.POST, DEFAULT_SCOPES, DEFAULT_AUDIENCES, DEFAULT_CLIENTIDS, null, null); validateParameter(methodConfig.getParameterConfigs().get(0), "serialized", false, null, TestBean.class, TestSerializer.class, String.class); }
Example #11
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testLevelOverridingWithDefaultOverrides() throws Exception { @Api( scopes = {"s0c", "s1c"}, audiences = {"a0c", "a1c"}, clientIds = {"c0c", "c1c"}, resource = "resource2", useDatastoreForAdditionalConfig = AnnotationBoolean.TRUE ) final class Test extends SimpleLevelOverridingInheritedApi { } ApiConfig config = createConfig(Test.class); annotationReader.loadEndpointClass(serviceContext, Test.class, config); annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods()); // All values overridden at a lower level, so nothing should change. verifySimpleLevelOverriding(config); }
Example #12
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testGenericParameterTypes() throws Exception { @Api final class Test <T> { @SuppressWarnings("unused") public void setT(T t) {} } ApiConfig config = createConfig(Test.class); annotationReader.loadEndpointMethods(serviceContext, Test.class, config.getApiClassConfig().getMethods()); ApiParameterConfig parameter = config.getApiClassConfig().getMethods() .get(methodToEndpointMethod(Test.class.getDeclaredMethod("setT", Object.class))) .getParameterConfigs() .get(0); assertEquals(ApiParameterConfig.Classification.UNKNOWN, parameter.getClassification()); }
Example #13
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
private <T> void genericParameterTypeTestImpl() throws Exception { @Api class Bar <T1> { @SuppressWarnings("unused") public void bar(T1 t1) {} } class Foo extends Bar<T> {} ApiConfig config = createConfig(Foo.class); annotationReader.loadEndpointMethods(serviceContext, Foo.class, config.getApiClassConfig().getMethods()); ApiParameterConfig parameter = config.getApiClassConfig().getMethods() .get(methodToEndpointMethod( Foo.class.getSuperclass().getDeclaredMethod("bar", Object.class))) .getParameterConfigs() .get(0); assertEquals(ApiParameterConfig.Classification.UNKNOWN, parameter.getClassification()); }
Example #14
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSuperclassWithoutApi() throws Exception { @Api class Foo { @SuppressWarnings("unused") public void foo() {} } class Bar extends Foo { @ApiMethod(name = "overridden") @Override public void foo() {} } ApiConfig config = createConfig(Bar.class); annotationReader.loadEndpointClass(serviceContext, Bar.class, config); annotationReader.loadEndpointMethods(serviceContext, Bar.class, config.getApiClassConfig().getMethods()); // Make sure method comes from Bar even though that class is not annotated with @Api. ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values()); assertEquals("overridden", methodConfig.getName()); assertEquals(Bar.class.getName() + ".foo", methodConfig.getFullJavaName()); }
Example #15
Source File: ApiMethodAnnotationConfigTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSetClientIdsIfSpecified_unspecified() throws Exception { testDefaults(); annotationConfig.setClientIdsIfSpecified(null); testDefaults(); String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; annotationConfig.setClientIdsIfSpecified(unspecified); testDefaults(); String[] clientIds = {"bleh", "more bleh"}; annotationConfig.setClientIdsIfSpecified(clientIds); annotationConfig.setClientIdsIfSpecified(unspecified); assertEquals(Arrays.asList(clientIds), config.getClientIds()); }
Example #16
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testGenericArrayRequest() throws Exception { @Api abstract class GenericArray<T> { @SuppressWarnings("unused") public void foo(@Named("collection") T[] t) {} } // TODO: remove with JDK8, dummy to force inclusion of GenericArray to InnerClass attribute // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2210448 GenericArray<Integer> dummy = new GenericArray<Integer>() {}; class Int32Array extends GenericArray<Integer> {} String apiConfigSource = g.generateConfig(Int32Array.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode methodNode = root.path("methods").path("myapi.int32Array.foo"); assertFalse(methodNode.isMissingNode()); verifyMethodRequestParameter(methodNode.get("request"), "collection", "int32", true, true); }
Example #17
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
/** * Test if the generated API has the expected method paths. First try this out without any * explicit paths. */ public void testMethodPaths_repeatRestPath() throws Exception { @SuppressWarnings("unused") @Api class Dates { @ApiMethod(httpMethod = "GET", path = "dates/{id1}/{id2}") public Date get(@Named("id1") String id1, @Named("id2") String id2) { return null; } @ApiMethod(httpMethod = "GET", path = "dates/{x}/{y}") public List<Date> listFromXY(@Named("x") String x, @Named("y") String y) { return null; } } try { g.generateConfig(Dates.class).get("myapi-v1.api"); fail("Multiple methods with same RESTful signature"); } catch (DuplicateRestPathException expected) { // expected } }
Example #18
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testEnumCollection() throws Exception { @Api class EnumParameters { @SuppressWarnings("unused") public void foo(@Named("outcome") Outcome outcome, @Named("outcomes1") Collection<Outcome> outcomes1, @Named("outcomes2") Outcome[] outcomes2) { } } String apiConfigSource = g.generateConfig(EnumParameters.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode request = root.path("methods").path("myapi.enumParameters.foo").path("request"); verifyMethodRequestParameter(request, "outcome", "string", true, false, "WON", "LOST", "TIE"); verifyMethodRequestParameter(request, "outcomes1", "string", true, true, "WON", "LOST", "TIE"); verifyMethodRequestParameter(request, "outcomes2", "string", true, true, "WON", "LOST", "TIE"); assertTrue(root.path("descriptor").path("schemas").path("Outcome").isMissingNode()); verifyEmptyMethodRequest(root, EnumParameters.class.getName() + ".foo"); }
Example #19
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSerializedPropertyInResourceSchema() throws Exception { class BazToDateSerializer extends DefaultValueSerializer<Baz, Date> { } @Api(transformers = {BazToDateSerializer.class, BarResourceSerializer.class}) class BarEndpoint { @SuppressWarnings("unused") public Bar getBar() { return null; } } String apiConfigSource = g.generateConfig(BarEndpoint.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode bar = root.path("descriptor").path("schemas").path("Bar"); verifyObjectPropertySchema(bar, "someBaz", "string", "date-time"); }
Example #20
Source File: JsonConfigWriterTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void writeConfigOrderIsPreserved() throws Exception { @Api(name = "onetoday", description = "OneToday API") final class OneToday { } @Api(name = "onetodayadmin", description = "One Today Admin API") final class OneTodayAdmin { } ApiConfigValidator validator = Mockito.mock(ApiConfigValidator.class); TypeLoader typeLoader = new TypeLoader(); JsonConfigWriter writer = new JsonConfigWriter(new TypeLoader(JsonConfigWriter.class.getClassLoader()), validator); ApiConfig oneToday = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday.class); ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class); oneToday.setName("onetoday"); oneToday.setVersion("v1"); oneTodayAdmin.setName("onetodayadmin"); oneTodayAdmin.setVersion("v1"); Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin)); Iterator<ApiKey> iterator = configs.keySet().iterator(); assertEquals(new ApiKey("onetoday", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next()); assertEquals(new ApiKey("onetodayadmin", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next()); }
Example #21
Source File: ApiAnnotationConfigTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSetClientIdsIfSpecified_unspecified() throws Exception { String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; EndpointMethod method = getResultNoParamsMethod(); annotationConfig.setScopesIfSpecified(unspecified); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method); assertEquals(ImmutableList.of(Constant.API_EXPLORER_CLIENT_ID), methodConfig.getClientIds()); String[] clientIds = {"bleh", "more bleh"}; annotationConfig.setClientIdsIfSpecified(clientIds); annotationConfig.setClientIdsIfSpecified(null); assertEquals(Arrays.asList(clientIds), config.getClientIds()); annotationConfig.setClientIdsIfSpecified(clientIds); annotationConfig.setClientIdsIfSpecified(unspecified); assertEquals(Arrays.asList(clientIds), config.getClientIds()); }
Example #22
Source File: ApiAnnotationConfigTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSetAudiencesIfSpecified_unspecified() throws Exception { String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; EndpointMethod method = getResultNoParamsMethod(); annotationConfig.setScopesIfSpecified(unspecified); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method); assertEquals(Collections.emptyList(), methodConfig.getAudiences()); String[] audiences = {"bleh", "more bleh"}; annotationConfig.setAudiencesIfSpecified(audiences); annotationConfig.setAudiencesIfSpecified(null); assertEquals(Arrays.asList(audiences), config.getAudiences()); annotationConfig.setAudiencesIfSpecified(audiences); annotationConfig.setAudiencesIfSpecified(unspecified); assertEquals(Arrays.asList(audiences), config.getAudiences()); }
Example #23
Source File: ApiAnnotationConfigTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testSetScopesIfSpecified_unspecified() throws Exception { String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; EndpointMethod method = getResultNoParamsMethod(); annotationConfig.setScopesIfSpecified(unspecified); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method); assertEquals(toScopeExpression(Constant.API_EMAIL_SCOPE), methodConfig.getScopeExpression()); String[] scopes = {"bleh", "more bleh"}; annotationConfig.setScopesIfSpecified(scopes); annotationConfig.setScopesIfSpecified(null); assertEquals(toScopeExpression(scopes), config.getScopeExpression()); annotationConfig.setScopesIfSpecified(scopes); annotationConfig.setScopesIfSpecified(unspecified); assertEquals(toScopeExpression(scopes), config.getScopeExpression()); }
Example #24
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testParameterAnnotations_javax() throws Exception { @Api class Endpoint { @SuppressWarnings("unused") public void method(@javax.inject.Named("foo") @javax.annotation.Nullable int foo) {} } ApiConfig config = createConfig(Endpoint.class); annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config); annotationReader.loadEndpointMethods(serviceContext, Endpoint.class, config.getApiClassConfig().getMethods()); ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values()); ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs()); validateParameter(parameterConfig, "foo", true, null, int.class, null, int.class); }
Example #25
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testParameterAnnotations() throws Exception { @Api class Endpoint { @SuppressWarnings("unused") public void method(@Named("foo") @Nullable @DefaultValue("4") int foo) {} } ApiConfig config = createConfig(Endpoint.class); annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config); annotationReader.loadEndpointMethods(serviceContext, Endpoint.class, config.getApiClassConfig().getMethods()); ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values()); ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs()); validateParameter(parameterConfig, "foo", true, "4", int.class, null, int.class); }
Example #26
Source File: ApiConfigAnnotationReaderTest.java From endpoints-java with Apache License 2.0 | 6 votes |
@Test public void testKnownParameterizedType() throws Exception { @Api class Bar <T1> { @SuppressWarnings("unused") public void bar(T1 t1) {} } class Foo extends Bar<Integer> {} ApiConfig config = createConfig(Foo.class); annotationReader.loadEndpointMethods(serviceContext, Foo.class, config.getApiClassConfig().getMethods()); ApiParameterConfig parameter = config.getApiClassConfig().getMethods() .get(methodToEndpointMethod( Foo.class.getSuperclass().getDeclaredMethod("bar", Object.class))) .getParameterConfigs() .get(0); assertEquals(ApiParameterConfig.Classification.API_PARAMETER, parameter.getClassification()); }
Example #27
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 5 votes |
@Test public void testAbstract() throws Exception { @Api(isAbstract = AnnotationBoolean.TRUE) class Test {} String apiConfigSource = g.generateConfig(Test.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); assertTrue(root.get("abstract").asBoolean()); }
Example #28
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 5 votes |
@Test public void testCollectionOfCollections() throws Exception { @Api class NestedCollections { @SuppressWarnings("unused") public void foo(@Named("authors") List<List<String>> authors) {} } try { g.generateConfig(NestedCollections.class).get("myapi-v1.api"); fail("Nested collections should fail"); } catch (NestedCollectionException expected) { // expected } }
Example #29
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 5 votes |
@Test public void testInvalidEnumInEndpointRequest() throws Exception { @Api class EnumParameter { @SuppressWarnings("unused") public void pick(Outcome outcome) {} } try { g.generateConfig(EnumParameter.class).get("myapi-v1.api"); fail("Enums should not be treated as resources"); } catch (MissingParameterNameException expected) { // expected } }
Example #30
Source File: AnnotationApiConfigGeneratorTest.java From endpoints-java with Apache License 2.0 | 5 votes |
@Test public void testMultipleCollectionRequests() throws Exception { @Api class MultipleCollections { @SuppressWarnings("unused") public void foo(@Named("ids") Long[] ids, @Named("authors") List<String> authors) {} } String apiConfigSource = g.generateConfig(MultipleCollections.class).get("myapi-v1.api"); ObjectNode root = objectMapper.readValue(apiConfigSource, ObjectNode.class); JsonNode methodNode = root.path("methods").path("myapi.multipleCollections.foo"); assertFalse(methodNode.isMissingNode()); verifyMethodRequestParameter(methodNode.get("request"), "ids", "int64", true, true); verifyMethodRequestParameter(methodNode.get("request"), "authors", "string", true, true); }