Search in sources :

Example 26 with ApiConfig

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

the class ApiConfigAnnotationReaderTest method testSuperclassWithoutApi.

@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());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) Foo(com.google.api.server.spi.testing.Foo) 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 27 with ApiConfig

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

the class LocalDiscoveryProviderTest method setUp.

@Before
public void setUp() {
    provider = new LocalDiscoveryProvider(ImmutableList.<ApiConfig>of(), generator, repository);
    when(generator.writeDiscovery(anyListOf(ApiConfig.class), any(DiscoveryContext.class), eq(repository))).thenReturn(Result.builder().setDiscoveryDocs(ImmutableMap.of(new ApiKey(NAME, VERSION, null), getPlaceholderDoc())).setDirectory(getPlaceholderDirectory()).build());
}
Also used : DiscoveryContext(com.google.api.server.spi.discovery.DiscoveryGenerator.DiscoveryContext) ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Before(org.junit.Before)

Example 28 with ApiConfig

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

the class ProxyingDiscoveryProviderTest method setUp.

@Before
public void setUp() throws Exception {
    ApiConfigLoader loader = new ApiConfigLoader();
    ServiceContext context = ServiceContext.create();
    ApiConfig apiConfig1 = loader.loadConfiguration(context, TestApi1.class);
    ApiConfig apiConfig2 = loader.loadConfiguration(context, TestApi2.class);
    ApiConfig apiConfig3 = loader.loadConfiguration(context, TestApiV2.class);
    ApiConfig.Factory factory = new ApiConfig.Factory();
    ApiConfig rewrittenApiConfig1 = factory.copy(apiConfig1);
    ApiConfig rewrittenApiConfig2 = factory.copy(apiConfig2);
    ApiConfig rewrittenApiConfig3 = factory.copy(apiConfig3);
    rewrittenApiConfig1.setRoot(REWRITTEN_ROOT);
    rewrittenApiConfig2.setRoot(REWRITTEN_ROOT);
    rewrittenApiConfig3.setRoot(REWRITTEN_ROOT);
    // Setup standard mocks on our discovery API.
    when(discovery.apis()).thenReturn(apis);
    when(apis.generateRest(any(com.google.api.services.discovery.model.ApiConfig.class))).thenReturn(restRequest);
    when(apis.generateRpc(any(com.google.api.services.discovery.model.ApiConfig.class))).thenReturn(rpcRequest);
    when(apis.generateDirectory(any(ApiConfigs.class))).thenReturn(directoryRequest);
    // Used by individual document tests
    when(configWriter.writeConfig(withConfigs(rewrittenApiConfig1, rewrittenApiConfig2))).thenReturn(ImmutableMap.of(V1_REWRITTEN_KEY, V1_JSON_API_CONFIG));
    // Used by directory tests
    when(configWriter.writeConfig(withConfigs(rewrittenApiConfig1, rewrittenApiConfig2, rewrittenApiConfig3))).thenReturn(ImmutableMap.of(V1_REWRITTEN_KEY, V1_JSON_API_CONFIG, V2_REWRITTEN_KEY, V2_JSON_API_CONFIG));
    provider = new ProxyingDiscoveryProvider(ImmutableList.of(apiConfig1, apiConfig2, apiConfig3), configWriter, discovery);
}
Also used : ApiConfigLoader(com.google.api.server.spi.config.ApiConfigLoader) ServiceContext(com.google.api.server.spi.ServiceContext) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) ApiConfigs(com.google.api.services.discovery.model.ApiConfigs) Before(org.junit.Before)

Example 29 with ApiConfig

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

the class JsonConfigWriter method writeConfig.

@Override
public Map<ApiKey, String> writeConfig(Iterable<? extends ApiConfig> configs) throws ApiConfigException {
    Multimap<ApiKey, ? extends ApiConfig> apisByKey = Multimaps.index(configs, new Function<ApiConfig, ApiKey>() {

        @Override
        public ApiKey apply(ApiConfig config) {
            return config.getApiKey();
        }
    });
    // This *must* retain the order of apisByKey so the lily_java_api BUILD rule has predictable
    // output order.
    Map<ApiKey, String> results = Maps.newLinkedHashMap();
    for (ApiKey apiKey : apisByKey.keySet()) {
        Collection<? extends ApiConfig> apiConfigs = apisByKey.get(apiKey);
        validator.validate(apiConfigs);
        results.put(apiKey, generateForApi(apiConfigs));
    }
    return results;
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Example 30 with ApiConfig

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

the class JsonConfigWriter method generateForApi.

private String generateForApi(Iterable<? extends ApiConfig> apiConfigs) throws ApiConfigException {
    ObjectNode root = objectMapper.createObjectNode();
    // First, generate api-wide configuration options, given any ApiConfig.
    ApiConfig apiConfig = Iterables.get(apiConfigs, 0);
    convertApi(root, apiConfig);
    convertApiAuth(root, apiConfig.getAuthConfig());
    convertApiFrontendLimits(root, apiConfig.getFrontendLimitsConfig());
    convertApiCacheControl(root, apiConfig.getCacheControlConfig());
    convertApiNamespace(root, apiConfig.getNamespaceConfig());
    // Next, generate config-specific configuration options,
    convertApiMethods(apiConfigs, root);
    return toString(root);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

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