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