Search in sources :

Example 1 with AuthLevel

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

the class AnnotationApiConfigGeneratorTest method testSimpleLevelOverriding.

@Test
public void testSimpleLevelOverriding() throws Exception {
    String apiConfigSource = g.generateConfig(SimpleLevelOverridingApi.class).get("myapi-v1.api");
    JsonNode root = objectMapper.readValue(apiConfigSource, JsonNode.class);
    JsonNode methods = root.path("methods");
    // myapi.resource1.noOverrides
    JsonNode noOverrides = methods.path("myapi.resource1.noOverrides");
    assertFalse(noOverrides.isMissingNode());
    verifyStrings(objectMapper.convertValue(noOverrides.path("scopes"), String[].class), new String[] { "s0a", "s1a" });
    verifyStrings(objectMapper.convertValue(noOverrides.path("audiences"), String[].class), new String[] { "a0a", "a1a" });
    verifyStrings(objectMapper.convertValue(noOverrides.path("clientIds"), String[].class), new String[] { "c0a", "c1a" });
    assertEquals("resource1", objectMapper.convertValue(noOverrides.path("path"), String.class));
    assertEquals(AuthLevel.REQUIRED, objectMapper.convertValue(noOverrides.path("authLevel"), AuthLevel.class));
    // myapi.resource1.overrides
    JsonNode overrides = methods.path("myapi.resource1.overrides");
    assertFalse(overrides.isMissingNode());
    verifyStrings(objectMapper.convertValue(overrides.path("scopes"), String[].class), new String[] { "s0b", "s1b" });
    verifyStrings(objectMapper.convertValue(overrides.path("audiences"), String[].class), new String[] { "a0b", "a1b" });
    verifyStrings(objectMapper.convertValue(overrides.path("clientIds"), String[].class), new String[] { "c0b", "c1b" });
    assertEquals("overridden", objectMapper.convertValue(overrides.path("path"), String.class));
    assertEquals(AuthLevel.OPTIONAL, objectMapper.convertValue(overrides.path("authLevel"), AuthLevel.class));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) AuthLevel(com.google.api.server.spi.config.AuthLevel) Test(org.junit.Test)

Example 2 with AuthLevel

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

the class ApiClassAnnotationConfigTest method testSetAuthLevelIfSpecified.

@Test
public void testSetAuthLevelIfSpecified() throws Exception {
    for (AuthLevel authLevel : AuthLevel.values()) {
        if (authLevel == AuthLevel.UNSPECIFIED) {
            // next test.
            continue;
        }
        annotationConfig.setAuthLevelIfSpecified(authLevel);
        Mockito.verify(config).setAuthLevel(authLevel);
    }
}
Also used : AuthLevel(com.google.api.server.spi.config.AuthLevel) Test(org.junit.Test)

Example 3 with AuthLevel

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

the class ApiAnnotationConfigTest method testSetAuthLevelIfSpecified.

@Test
public void testSetAuthLevelIfSpecified() throws Exception {
    for (AuthLevel authLevel : AuthLevel.values()) {
        if (authLevel == AuthLevel.UNSPECIFIED) {
            // next test.
            continue;
        }
        annotationConfig.setAuthLevelIfSpecified(authLevel);
        assertEquals(authLevel, config.getAuthLevel());
        ApiMethodConfig methodConfig = config.getApiClassConfig().getMethods().getOrCreate(getResultNoParamsMethod());
        assertEquals(authLevel, methodConfig.getAuthLevel());
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) AuthLevel(com.google.api.server.spi.config.AuthLevel) Test(org.junit.Test)

Example 4 with AuthLevel

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

the class ApiMethodAnnotationConfigTest method testSetAuthLevelIfSpecified.

@Test
public void testSetAuthLevelIfSpecified() throws Exception {
    for (AuthLevel authLevel : AuthLevel.values()) {
        if (authLevel == AuthLevel.UNSPECIFIED) {
            // next test.
            continue;
        }
        annotationConfig.setAuthLevelIfSpecified(authLevel);
        assertEquals(authLevel, config.getAuthLevel());
    }
}
Also used : AuthLevel(com.google.api.server.spi.config.AuthLevel) Test(org.junit.Test)

Aggregations

AuthLevel (com.google.api.server.spi.config.AuthLevel)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)1 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)1