Search in sources :

Example 1 with ApiConfigAnnotationReader

use of com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method multipleResourceParametersErrorMessage.

/**
 * Tests that if a method has multiple resource parameters, a helpful message is thrown.
 */
@Test
public void multipleResourceParametersErrorMessage() throws Exception {
    final class Endpoint {

        @SuppressWarnings("unused")
        public void get(Bean bean1, Bean bean2) {
        }
    }
    new ApiConfigAnnotationReader().loadEndpointMethods(serviceContext, Endpoint.class, apiConfig.getApiClassConfig().getMethods());
    try {
        writer.writeConfig(Collections.singleton(apiConfig));
        fail("Method with multiple resources should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage()).contains("cannot have multiple resource parameters");
    }
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) Test(org.junit.Test)

Example 2 with ApiConfigAnnotationReader

use of com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method idIsASpecialCaseForPropertyConflicts.

@Test
public void idIsASpecialCaseForPropertyConflicts() throws Exception {
    final class Endpoint {

        @SuppressWarnings("unused")
        public void set(@Named("id") String id, IdBean resource) {
        }

        @SuppressWarnings("unused")
        public IdBean get(@Named("id") String id) {
            return null;
        }

        @SuppressWarnings("unused")
        public IdBean update(@Named("id") String id) {
            return null;
        }

        @SuppressWarnings("unused")
        public void remove(@Named("id") String id) {
        }
    }
    new ApiConfigAnnotationReader().loadEndpointMethods(serviceContext, Endpoint.class, apiConfig.getApiClassConfig().getMethods());
    writer.writeConfig(Collections.singleton(apiConfig));
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) Named(javax.inject.Named) Test(org.junit.Test)

Example 3 with ApiConfigAnnotationReader

use of com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method enumResponseIsBlocked.

@Test
public void enumResponseIsBlocked() throws Exception {
    final class Endpoint {

        @SuppressWarnings("unused")
        public TestEnum get() {
            return TestEnum.A;
        }
    }
    new ApiConfigAnnotationReader().loadEndpointMethods(serviceContext, Endpoint.class, apiConfig.getApiClassConfig().getMethods());
    try {
        writer.writeConfig(Collections.singleton(apiConfig));
        fail();
    } catch (InvalidReturnTypeException e) {
    // Expected.
    }
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) InvalidReturnTypeException(com.google.api.server.spi.config.validation.InvalidReturnTypeException) Test(org.junit.Test)

Example 4 with ApiConfigAnnotationReader

use of com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method writeConfigWithParameterizedTypeNoTransformerConfig.

/**
 * This tests writeConfig with a parameterized type, which should be supported by adding a schema
 * named Qux_String.
 */
@Test
public void writeConfigWithParameterizedTypeNoTransformerConfig() throws Exception {
    final class Endpoint {

        @SuppressWarnings("unused")
        public ParameterizedBean get(@Named("date") String id) {
            return null;
        }
    }
    new ApiConfigAnnotationReader().loadEndpointMethods(serviceContext, Endpoint.class, apiConfig.getApiClassConfig().getMethods());
    Map<ApiKey, String> apiKeyStringMap = writer.writeConfig(Collections.singleton(apiConfig));
    String configString = Iterables.getFirst(apiKeyStringMap.values(), null);
    assertThat(configString).contains("Qux_String");
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) Named(javax.inject.Named) ApiKey(com.google.api.server.spi.config.model.ApiKey) Test(org.junit.Test)

Example 5 with ApiConfigAnnotationReader

use of com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader in project endpoints-java by cloudendpoints.

the class JsonConfigWriterTest method bodyFieldConflictsWithParameter.

@Test
@Ignore("ignored until we find a proper solution")
public void bodyFieldConflictsWithParameter() throws Exception {
    final class Endpoint {

        @SuppressWarnings("unused")
        public void set(@Named("date") String id, Bean resource) {
        }
    }
    new ApiConfigAnnotationReader().loadEndpointMethods(serviceContext, Endpoint.class, apiConfig.getApiClassConfig().getMethods());
    try {
        writer.writeConfig(Collections.singleton(apiConfig));
        fail();
    } catch (PropertyParameterNameConflictException e) {
    // Expected.
    }
}
Also used : ApiConfigAnnotationReader(com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader) Named(javax.inject.Named) PropertyParameterNameConflictException(com.google.api.server.spi.config.validation.PropertyParameterNameConflictException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ApiConfigAnnotationReader (com.google.api.server.spi.config.annotationreader.ApiConfigAnnotationReader)15 Test (org.junit.Test)9 TypeLoader (com.google.api.server.spi.TypeLoader)6 ApiConfigLoader (com.google.api.server.spi.config.ApiConfigLoader)5 Named (javax.inject.Named)5 Before (org.junit.Before)4 ServiceContext (com.google.api.server.spi.ServiceContext)3 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)3 ApiKey (com.google.api.server.spi.config.model.ApiKey)2 SchemaRepository (com.google.api.server.spi.config.model.SchemaRepository)2 InvalidReturnTypeException (com.google.api.server.spi.config.validation.InvalidReturnTypeException)2 EndpointsPrettyPrinter (com.google.api.server.spi.response.EndpointsPrettyPrinter)2 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)1 ApiConfigValidator (com.google.api.server.spi.config.validation.ApiConfigValidator)1 PropertyParameterNameConflictException (com.google.api.server.spi.config.validation.PropertyParameterNameConflictException)1 DiscoveryGenerator (com.google.api.server.spi.discovery.DiscoveryGenerator)1