Search in sources :

Example 16 with TypeLoader

use of com.google.api.server.spi.TypeLoader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method writeConfigOrderIsPreservedMulticlass.

@Test
public void writeConfigOrderIsPreservedMulticlass() throws Exception {
    @Api(name = "onetoday", description = "OneToday API")
    final class OneToday {
    }
    @Api(name = "onetoday", description = "OneToday API")
    final class OneToday2 {
    }
    @Api(name = "onetodayadmin", description = "One Today Admin API")
    final class OneTodayAdmin {
    }
    @Api(name = "onetodayadmin", description = "One Today Admin API")
    final class OneTodayAdmin2 {
    }
    ApiConfigValidator validator = Mockito.mock(ApiConfigValidator.class);
    TypeLoader typeLoader = new TypeLoader();
    JsonConfigWriter writer = new JsonConfigWriter(new TypeLoader(JsonConfigWriter.class.getClassLoader()), validator);
    ApiConfig oneToday = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday.class);
    ApiConfig oneToday2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday2.class);
    ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class);
    ApiConfig oneTodayAdmin2 = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin2.class);
    oneToday.setName("onetoday");
    oneToday.setVersion("v1");
    oneToday2.setName("onetoday");
    oneToday2.setVersion("v1");
    oneTodayAdmin.setName("onetodayadmin");
    oneTodayAdmin.setVersion("v1");
    oneTodayAdmin2.setName("onetodayadmin");
    oneTodayAdmin2.setVersion("v1");
    Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin, oneTodayAdmin2, oneToday2));
    Iterator<ApiKey> iterator = configs.keySet().iterator();
    assertEquals(new ApiKey("onetoday", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
    assertEquals(new ApiKey("onetodayadmin", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfigValidator(com.google.api.server.spi.config.validation.ApiConfigValidator) TypeLoader(com.google.api.server.spi.TypeLoader) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 17 with TypeLoader

use of com.google.api.server.spi.TypeLoader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method writeConfigOrderIsPreserved.

@Test
public void writeConfigOrderIsPreserved() throws Exception {
    @Api(name = "onetoday", description = "OneToday API")
    final class OneToday {
    }
    @Api(name = "onetodayadmin", description = "One Today Admin API")
    final class OneTodayAdmin {
    }
    ApiConfigValidator validator = Mockito.mock(ApiConfigValidator.class);
    TypeLoader typeLoader = new TypeLoader();
    JsonConfigWriter writer = new JsonConfigWriter(new TypeLoader(JsonConfigWriter.class.getClassLoader()), validator);
    ApiConfig oneToday = new ApiConfig.Factory().create(serviceContext, typeLoader, OneToday.class);
    ApiConfig oneTodayAdmin = new ApiConfig.Factory().create(serviceContext, typeLoader, OneTodayAdmin.class);
    oneToday.setName("onetoday");
    oneToday.setVersion("v1");
    oneTodayAdmin.setName("onetodayadmin");
    oneTodayAdmin.setVersion("v1");
    Map<ApiKey, String> configs = writer.writeConfig(Lists.newArrayList(oneToday, oneTodayAdmin));
    Iterator<ApiKey> iterator = configs.keySet().iterator();
    assertEquals(new ApiKey("onetoday", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
    assertEquals(new ApiKey("onetodayadmin", "v1", "https://myapp.appspot.com/_ah/api"), iterator.next());
}
Also used : ApiKey(com.google.api.server.spi.config.model.ApiKey) ApiConfigValidator(com.google.api.server.spi.config.validation.ApiConfigValidator) TypeLoader(com.google.api.server.spi.TypeLoader) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 18 with TypeLoader

use of com.google.api.server.spi.TypeLoader in project endpoints-java by cloudendpoints.

the class RestServletRequestParamReaderTest method setUp.

@Before
public void setUp() throws Exception {
    endpointMethod = EndpointMethod.create(TestApi.class, TestApi.class.getMethod("test", Long.TYPE, List.class, SimpleDate.class, TestResource.class));
    request = new MockHttpServletRequest();
    ServiceContext serviceContext = ServiceContext.create();
    serializationConfig = new ApiSerializationConfig();
    TypeLoader typeLoader = new TypeLoader();
    apiConfig = new ApiConfig.Factory().create(serviceContext, typeLoader, TestApi.class);
    ApiConfigAnnotationReader annotationReader = new ApiConfigAnnotationReader();
    annotationReader.loadEndpointClass(serviceContext, TestApi.class, apiConfig);
    annotationReader.loadEndpointMethods(serviceContext, TestApi.class, apiConfig.getApiClassConfig().getMethods());
    methodConfig = apiConfig.getApiClassConfig().getMethods().get(endpointMethod);
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServiceContext(com.google.api.server.spi.ServiceContext) TypeLoader(com.google.api.server.spi.TypeLoader) ApiSerializationConfig(com.google.api.server.spi.config.model.ApiSerializationConfig) Before(org.junit.Before)

Aggregations

TypeLoader (com.google.api.server.spi.TypeLoader)18 Before (org.junit.Before)11 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)7 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)6 ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)6 SchemaRepository (com.google.api.server.spi.config.model.SchemaRepository)5 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)5 ServiceContext (com.google.api.server.spi.ServiceContext)4 TestEndpoint (com.google.api.server.spi.testing.TestEndpoint)4 ApiKey (com.google.api.server.spi.config.model.ApiKey)3 File (java.io.File)3 URLClassLoader (java.net.URLClassLoader)3 Test (org.junit.Test)3 Api (com.google.api.server.spi.config.Api)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 EndpointsPrettyPrinter (com.google.api.server.spi.response.EndpointsPrettyPrinter)2 Map (java.util.Map)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1