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());
}
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());
}
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);
}
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;
}
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);
}
Aggregations