ApiAnnotationConfig { public void setScopesIfSpecified(String[] scopes) { if (!AnnotationUtil.isUnspecified(scopes)) { config.setScopeExpression(AuthScopeExpressions.interpret(scopes)); } } ApiAnnotationConfig(ApiConfig config); ApiConfig getConfig(); void setRootIfNotEmpty(String root); void setNameIfNotEmpty(String name); void setCanonicalNameIfNotEmpty(String canonicalName); void setVersionIfNotEmpty(String version); void setTitleIfNotEmpty(String title); void setDescriptionIfNotEmpty(String description); void setDocumentationLinkIfNotEmpty(String documentationLink); void setBackendRootIfNotEmpty(String backendRoot); void setIsAbstractIfSpecified(AnnotationBoolean isAbstract); void setIsDefaultVersionIfSpecified(AnnotationBoolean defaultVersion); void setIsDiscoverableIfSpecified(AnnotationBoolean discoverable); void setUseDatastoreIfSpecified(AnnotationBoolean useDatastore); void setResourceIfNotEmpty(String resource); void setAuthLevelIfSpecified(AuthLevel authLevel); void setScopesIfSpecified(String[] scopes); void setAudiencesIfSpecified(String[] audiences); void setIssuersIfSpecified(ApiIssuerConfigs issuers); void setIssuerAudiencesIfSpecified(ApiIssuerAudienceConfig issuerAudiences); void setClientIdsIfSpecified(String[] clientIds); void setAuthenticatorsIfSpecified(Class<? extends Authenticator>[] authenticators); void setPeerAuthenticatorsIfSpecified(
      Class<? extends PeerAuthenticator>[] peerAuthenticators); void setApiKeyRequiredIfSpecified(AnnotationBoolean apiKeyRequired); void setApiLimitMetrics(ApiLimitMetric[] apiLimitMetrics);  }
@Test public void testSetScopesIfSpecified() throws Exception { String[] scopes = { "foo", "bar" }; annotationConfig.setScopesIfSpecified(scopes); assertEquals(toScopeExpression(scopes), config.getScopeExpression()); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(getResultNoParamsMethod()); assertEquals(toScopeExpression(scopes), methodConfig.getScopeExpression()); }
@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()); }
@Test public void testSetScopesIfSpecified_unspecified() throws Exception { String[] unspecified = {Api.UNSPECIFIED_STRING_FOR_LIST}; EndpointMethod method = getResultNoParamsMethod(); annotationConfig.setScopesIfSpecified(unspecified); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(method); assertEquals(toScopeExpression(Constant.API_EMAIL_SCOPE), methodConfig.getScopeExpression()); String[] scopes = {"bleh", "more bleh"}; annotationConfig.setScopesIfSpecified(scopes); annotationConfig.setScopesIfSpecified(null); assertEquals(toScopeExpression(scopes), config.getScopeExpression()); annotationConfig.setScopesIfSpecified(scopes); annotationConfig.setScopesIfSpecified(unspecified); assertEquals(toScopeExpression(scopes), config.getScopeExpression()); }