Search in sources :

Example 26 with ApiMethodConfig

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

the class ApiAnnotationConfigTest method testSetClientIdsIfSpecified_unspecified.

@Test
public void testSetClientIdsIfSpecified_unspecified() throws Exception {
    String[] unspecified = { Api.UNSPECIFIED_STRING_FOR_LIST };
    EndpointMethod method = getResultNoParamsMethod();
    annotationConfig.setScopesIfSpecified(unspecified);
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(ImmutableList.of(Constant.API_EXPLORER_CLIENT_ID), methodConfig.getClientIds());
    String[] clientIds = { "bleh", "more bleh" };
    annotationConfig.setClientIdsIfSpecified(clientIds);
    annotationConfig.setClientIdsIfSpecified(null);
    assertEquals(Arrays.asList(clientIds), config.getClientIds());
    annotationConfig.setClientIdsIfSpecified(clientIds);
    annotationConfig.setClientIdsIfSpecified(unspecified);
    assertEquals(Arrays.asList(clientIds), config.getClientIds());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 27 with ApiMethodConfig

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

the class ApiAnnotationConfigTest method testSetAuthLevelIfSpecified_unspecified.

@Test
public void testSetAuthLevelIfSpecified_unspecified() throws Exception {
    EndpointMethod method = getResultNoParamsMethod();
    annotationConfig.setAuthLevelIfSpecified(AuthLevel.UNSPECIFIED);
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(AuthLevel.NONE, methodConfig.getAuthLevel());
    annotationConfig.setAuthLevelIfSpecified(AuthLevel.REQUIRED);
    assertEquals(AuthLevel.REQUIRED, config.getAuthLevel());
    annotationConfig.setAuthLevelIfSpecified(AuthLevel.UNSPECIFIED);
    assertEquals(AuthLevel.REQUIRED, config.getAuthLevel());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 28 with ApiMethodConfig

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

the class ApiAnnotationConfigTest method testSetAudiencesIfSpecified_unspecified.

@Test
public void testSetAudiencesIfSpecified_unspecified() throws Exception {
    String[] unspecified = { Api.UNSPECIFIED_STRING_FOR_LIST };
    EndpointMethod method = getResultNoParamsMethod();
    annotationConfig.setScopesIfSpecified(unspecified);
    ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method);
    assertEquals(Collections.emptyList(), methodConfig.getAudiences());
    String[] audiences = { "bleh", "more bleh" };
    annotationConfig.setAudiencesIfSpecified(audiences);
    annotationConfig.setAudiencesIfSpecified(null);
    assertEquals(Arrays.asList(audiences), config.getAudiences());
    annotationConfig.setAudiencesIfSpecified(audiences);
    annotationConfig.setAudiencesIfSpecified(unspecified);
    assertEquals(Arrays.asList(audiences), config.getAudiences());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 29 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig 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 30 with ApiMethodConfig

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

the class ApiConfigValidator method validate.

/**
 * Validates all configurations for a single API.  Makes sure the API-level configuration matches
 * for all classes and that the contained configuration is valid and can be turned into a *.api
 * file.  Only checks for swarm-specific validity.  Apiary FE may still dislike a config for its
 * own reasons.
 *
 * @throws ApiConfigInvalidException on any invalid API-wide configuration.
 * @throws ApiClassConfigInvalidException on any invalid API class configuration.
 * @throws ApiMethodConfigInvalidException on any invalid API method configuration.
 * @throws ApiParameterConfigInvalidException on any invalid API parameter configuration.
 */
public void validate(Iterable<? extends ApiConfig> apiConfigs) throws ApiConfigInvalidException, ApiClassConfigInvalidException, ApiMethodConfigInvalidException, ApiParameterConfigInvalidException {
    if (Iterables.isEmpty(apiConfigs)) {
        return;
    }
    Map<String, ApiMethodConfig> restfulSignatures = Maps.newHashMap();
    Iterator<? extends ApiConfig> i = apiConfigs.iterator();
    ApiConfig first = i.next();
    validate(first, restfulSignatures);
    while (i.hasNext()) {
        ApiConfig config = i.next();
        Iterable<ApiConfigInconsistency<Object>> inconsistencies = config.getConfigurationInconsistencies(first);
        if (!Iterables.isEmpty(inconsistencies)) {
            throw new InconsistentApiConfigurationException(config, first, inconsistencies);
        }
        validate(config, restfulSignatures);
    }
}
Also used : ApiConfigInconsistency(com.google.api.server.spi.config.ApiConfigInconsistency) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2