use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testCachedNamesAreUsed.
@Test
public void testCachedNamesAreUsed() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(@Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Named("foo3") String f3) {
}
}
Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
endpointMethod.setParameterNames(ImmutableList.of("name1", "name2", "name3"));
String requestString = "{\"name1\":\"v1\", \"foo2\":\"v2\", \"name3\":\"v3\"}";
Object[] params = readParameters(requestString, endpointMethod);
assertEquals(3, params.length);
assertEquals("v1", params[0]);
assertNull(params[1]);
assertEquals("v3", params[2]);
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ServletRequestParamReaderTest method testNamesAreCached.
@Test
public void testNamesAreCached() throws Exception {
class Test {
@SuppressWarnings("unused")
public void foo(@Nullable @Named("foo1") String f1, @Nullable @Named("foo2") String f2, @Nullable @Named("foo3") String f3) {
}
}
Method method = Test.class.getDeclaredMethod("foo", String.class, String.class, String.class);
EndpointMethod endpointMethod = EndpointMethod.create(method.getDeclaringClass(), method);
readParameters("{}", endpointMethod);
List<String> parameterNames = endpointMethod.getParameterNames();
assertEquals(3, parameterNames.size());
assertEquals("foo1", parameterNames.get(0));
assertEquals("foo2", parameterNames.get(1));
assertEquals("foo3", parameterNames.get(2));
}
use of com.google.api.server.spi.EndpointMethod 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, methodConfig, systemService, expectedResponse, params);
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiAnnotationConfigTest method testSetScopesIfSpecified_empty.
@Test
public void testSetScopesIfSpecified_empty() throws Exception {
String[] empty = {};
annotationConfig.setScopesIfSpecified(empty);
EndpointMethod method = getResultNoParamsMethod();
ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
assertEquals(toScopeExpression(), methodConfig.getScopeExpression());
String[] scopes = { "bleh", "more bleh" };
annotationConfig.setScopesIfSpecified(scopes);
annotationConfig.setScopesIfSpecified(empty);
assertEquals(toScopeExpression(), config.getScopeExpression());
}
use of com.google.api.server.spi.EndpointMethod in project endpoints-java by cloudendpoints.
the class ApiAnnotationConfigTest method testSetClientIdsIfSpecified_empty.
@Test
public void testSetClientIdsIfSpecified_empty() throws Exception {
String[] empty = {};
annotationConfig.setClientIdsIfSpecified(empty);
EndpointMethod method = getResultNoParamsMethod();
ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
assertEquals(Collections.emptyList(), methodConfig.getClientIds());
String[] clientIds = { "bleh", "more bleh" };
annotationConfig.setClientIdsIfSpecified(clientIds);
annotationConfig.setClientIdsIfSpecified(empty);
assertEquals(Collections.emptyList(), config.getClientIds());
}
Aggregations