use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class EndpointsMethodHandlerTest method rootMethodHandler.
@Test
public void rootMethodHandler() throws Exception {
EndpointMethod method = systemService.resolveService("TestEndpoint", "root");
ApiMethodConfig methodConfig = new ApiMethodConfig(method, typeLoader, apiConfig.getApiClassConfig());
methodConfig.setPath("/root");
TestMethodHandler handler = new TestMethodHandler(ServletInitializationParameters.builder().build(), method, methodConfig, systemService, 200);
assertThat(handler.getRestPath()).isEqualTo("root");
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiMethodAnnotationConfigTest method setUp.
@Before
public void setUp() throws Exception {
serializationConfig = new ApiSerializationConfig();
Mockito.when(apiClassConfig.getApiConfig()).thenReturn(apiConfig);
Mockito.when(apiClassConfig.getAuthLevel()).thenReturn(AuthLevel.NONE);
Mockito.when(apiClassConfig.getScopeExpression()).thenReturn(defaultScopeExpression);
Mockito.when(apiClassConfig.getAudiences()).thenReturn(defaultAudiences);
Mockito.when(apiClassConfig.getClientIds()).thenReturn(defaultClientIds);
Mockito.<List<Class<? extends Authenticator>>>when(apiClassConfig.getAuthenticators()).thenReturn(defaultAuthenticators);
Mockito.<List<Class<? extends PeerAuthenticator>>>when(apiClassConfig.getPeerAuthenticators()).thenReturn(defaultPeerAuthenticators);
Mockito.when(apiClassConfig.getApiClassJavaSimpleName()).thenReturn(TestEndpoint.class.getSimpleName());
Mockito.when(apiConfig.getSerializationConfig()).thenReturn(serializationConfig);
EndpointMethod method = EndpointMethod.create(TestEndpoint.class, TestEndpoint.class.getMethod("overrideMethod1"));
config = new ApiMethodConfig(method, new TypeLoader(), apiClassConfig);
annotationConfig = new ApiMethodAnnotationConfig(config);
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiConfigValidatorTest method testNonuniqueJavaNames.
@Test
public void testNonuniqueJavaNames() throws Exception {
// Steal two overloaded methods from another class.
EndpointMethod method1 = mock(EndpointMethod.class);
when(method1.getMethod()).thenReturn(DuplicateMethodEndpoint.class.getMethod("foo", String.class));
doReturn(TestEndpoint.class).when(method1).getEndpointClass();
when(method1.getReturnType()).thenReturn((TypeToken) TypeToken.of(Void.class));
EndpointMethod method2 = mock(EndpointMethod.class);
when(method2.getMethod()).thenReturn(DuplicateMethodEndpoint.class.getMethod("foo", Integer.class));
doReturn(TestEndpoint.class).when(method2).getEndpointClass();
when(method2.getReturnType()).thenReturn((TypeToken) TypeToken.of(Void.class));
config.getApiClassConfig().getMethods().getOrCreate(method1).setPath("fn1");
config.getApiClassConfig().getMethods().getOrCreate(method2).setPath("fn2");
try {
validator.validate(config);
fail("Expected OverloadedMethodException.");
} catch (OverloadedMethodException expected) {
}
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiClassConfigTest method testAddMethodDuplicates.
@Test
public void testAddMethodDuplicates() throws Exception {
assertEquals(0, config.getMethods().size());
EndpointMethod method1 = getGetDateMethod();
ApiMethodConfig methodConfig1 = config.getMethods().getOrCreate(method1);
ApiMethodConfig methodConfig2 = config.getMethods().getOrCreate(method1);
assertEquals(1, config.getMethods().size());
assertEquals(methodConfig1, methodConfig2);
EndpointMethod method2 = getResultNoParamsMethod();
methodConfig1 = config.getMethods().getOrCreate(method2);
methodConfig2 = config.getMethods().getOrCreate(method2);
assertEquals(2, config.getMethods().size());
assertEquals(methodConfig1, methodConfig2);
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiClassConfigTest method testAddMethod.
@Test
public void testAddMethod() throws Exception {
assertEquals(0, config.getMethods().size());
EndpointMethod method = getResultNoParamsMethod();
ApiMethodConfig methodConfig = config.getMethods().getOrCreate(method);
Map<EndpointMethod, ApiMethodConfig> methodConfigs = config.getMethods();
assertEquals(1, methodConfigs.size());
assertEquals(methodConfig, methodConfigs.get(method));
}
Aggregations