Search in sources :

Example 6 with EndpointMethod

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");
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 7 with EndpointMethod

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);
}
Also used : TestEndpoint(com.google.api.server.spi.testing.TestEndpoint) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointsPeerAuthenticator(com.google.api.server.spi.auth.EndpointsPeerAuthenticator) PassPeerAuthenticator(com.google.api.server.spi.testing.PassPeerAuthenticator) PeerAuthenticator(com.google.api.server.spi.config.PeerAuthenticator) EndpointMethod(com.google.api.server.spi.EndpointMethod) TypeLoader(com.google.api.server.spi.TypeLoader) ApiSerializationConfig(com.google.api.server.spi.config.model.ApiSerializationConfig) EndpointsPeerAuthenticator(com.google.api.server.spi.auth.EndpointsPeerAuthenticator) PassAuthenticator(com.google.api.server.spi.testing.PassAuthenticator) PassPeerAuthenticator(com.google.api.server.spi.testing.PassPeerAuthenticator) Authenticator(com.google.api.server.spi.config.Authenticator) EndpointsAuthenticator(com.google.api.server.spi.auth.EndpointsAuthenticator) PeerAuthenticator(com.google.api.server.spi.config.PeerAuthenticator) Before(org.junit.Before)

Example 8 with EndpointMethod

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) {
    }
}
Also used : DuplicateMethodEndpoint(com.google.api.server.spi.testing.DuplicateMethodEndpoint) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 9 with EndpointMethod

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);
}
Also used : EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 10 with EndpointMethod

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));
}
Also used : EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Aggregations

EndpointMethod (com.google.api.server.spi.EndpointMethod)26 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)14 Test (org.junit.Test)14 Method (java.lang.reflect.Method)6 Annotation (java.lang.annotation.Annotation)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Named (com.google.api.server.spi.config.Named)2 Nullable (com.google.api.server.spi.config.Nullable)2 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)2 BadRequestException (com.google.api.server.spi.response.BadRequestException)2 TypeToken (com.google.common.reflect.TypeToken)2 Map (java.util.Map)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MethodHierarchyReader (com.google.api.server.spi.MethodHierarchyReader)1 TypeLoader (com.google.api.server.spi.TypeLoader)1 EndpointsAuthenticator (com.google.api.server.spi.auth.EndpointsAuthenticator)1 EndpointsPeerAuthenticator (com.google.api.server.spi.auth.EndpointsPeerAuthenticator)1 User (com.google.api.server.spi.auth.common.User)1 Authenticator (com.google.api.server.spi.config.Authenticator)1