ApiAnnotationConfig { public void setAuthLevelIfSpecified(AuthLevel authLevel) { if (authLevel != AuthLevel.UNSPECIFIED) { config.setAuthLevel(authLevel); } } 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 testSetAuthLevelIfSpecified() throws Exception { for (AuthLevel authLevel : AuthLevel.values()) { if (authLevel == AuthLevel.UNSPECIFIED) { continue; } annotationConfig.setAuthLevelIfSpecified(authLevel); assertEquals(authLevel, config.getAuthLevel()); ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(getResultNoParamsMethod()); assertEquals(authLevel, methodConfig.getAuthLevel()); } }
@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()); }