Search in sources :

Example 51 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testServiceWithOverridingReference.

@Test
public void testServiceWithOverridingReference() throws Exception {
    ApiConfig config = createConfig(ReferenceOverridingEndpoint.class);
    annotationReader.loadEndpointClass(serviceContext, ReferenceOverridingEndpoint.class, config);
    assertEquals("api", config.getName());
    assertEquals("v3", config.getVersion());
    assertEquals("more overridden description", config.getDescription());
    assertTrue(config.getIsDefaultVersion());
    assertTrue(config.getUseDatastore());
    ApiAuthConfig auth = config.getAuthConfig();
    assertTrue(auth.getAllowCookieAuth());
    ApiFrontendLimitsConfig frontendLimits = config.getFrontendLimitsConfig();
    assertEquals(1, frontendLimits.getUnregisteredUserQps());
    assertEquals(4, frontendLimits.getUnregisteredQps());
    ApiCacheControlConfig cacheControl = config.getCacheControlConfig();
    assertEquals(2, cacheControl.getMaxAge());
    assertEquals(ApiCacheControl.Type.PUBLIC, cacheControl.getType());
    annotationReader.loadEndpointMethods(serviceContext, ReferenceOverridingEndpoint.class, config.getApiClassConfig().getMethods());
    String[] defaultScopes = { "ss0b", "ss1b" };
    String[] defaultAudiences = { "aa0b", "aa1b" };
    String[] defaultClientIds = { "cc0b", "cc1b" };
    assertEquals(8, config.getApiClassConfig().getMethods().size());
    ApiMethodConfig getFoo = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(ReferenceOverridingEndpoint.class.getMethod("getFoo", String.class)));
    validateMethod(getFoo, "foos.get3", "foos/{id}", ApiMethod.HttpMethod.GET, defaultScopes, defaultAudiences, defaultClientIds, ImmutableList.of(PassAuthenticator.class), ImmutableList.of(PassPeerAuthenticator.class));
    assertEquals(1, getFoo.getParameterConfigs().size());
    validateParameter(getFoo.getParameterConfigs().get(0), "id", false, null, String.class);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiFrontendLimitsConfig(com.google.api.server.spi.config.model.ApiFrontendLimitsConfig) 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) ApiCacheControlConfig(com.google.api.server.spi.config.model.ApiCacheControlConfig) ApiAuthConfig(com.google.api.server.spi.config.model.ApiAuthConfig) Test(org.junit.Test)

Example 52 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testSimpleContravarianceEndpoint.

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

Example 53 with ApiMethodConfig

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

the class ServletRequestParamReaderTest method testUserInjectionThrowsExceptionIfRequired.

@Test
public void testUserInjectionThrowsExceptionIfRequired() throws Exception {
    @SuppressWarnings("unused")
    class TestUser {

        @SuppressWarnings("unused")
        public void getUser(User user) {
        }
    }
    ApiMethodConfig methodConfig = Mockito.mock(ApiMethodConfig.class);
    when(methodConfig.getAuthLevel()).thenReturn(AuthLevel.REQUIRED);
    methodConfig.setAuthLevel(AuthLevel.REQUIRED);
    try {
        Method method = TestUser.class.getDeclaredMethod("getUser", User.class);
        readParameters("{}", EndpointMethod.create(method.getDeclaringClass(), method), methodConfig, null, null);
        fail("expected unauthorized method exception");
    } catch (UnauthorizedException ex) {
    // expected
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) User(com.google.api.server.spi.auth.common.User) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 54 with ApiMethodConfig

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

the class EndpointsMethodHandlerTest method createTestHandler.

private TestMethodHandler createTestHandler(String methodName, Object expectedResponse, Object... params) throws Exception {
    EndpointMethod method = systemService.resolveService("TestEndpoint", methodName);
    ApiMethodConfig methodConfig = new ApiMethodConfig(method, typeLoader, apiConfig.getApiClassConfig());
    return new TestMethodHandler(ServletInitializationParameters.builder().build(), method, apiConfig, methodConfig, systemService, expectedResponse, params);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2