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());
}
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());
}
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());
}
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);
}
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);
}
}
Aggregations