Search in sources :

Example 1 with PolicyEntity

use of io.gravitee.management.model.PolicyEntity in project gravitee-management-rest-api by gravitee-io.

the class PoliciesResourceTest method shouldGetPoliciesList.

@Test
public void shouldGetPoliciesList() {
    HashSet<PolicyEntity> policyEntities = new HashSet<>();
    PolicyEntity policyEntity = new PolicyEntity();
    policyEntities.add(policyEntity);
    policyEntity.setId("my-api");
    policyEntity.setName("My Api");
    when(policyService.findAll()).thenReturn(policyEntities);
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Set entity = response.readEntity(Set.class);
    assertFalse("not empty", entity.isEmpty());
    assertEquals("one element", 1, entity.size());
    Object o = entity.iterator().next();
    assertTrue(o instanceof LinkedHashMap);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertEquals("id", "my-api", elt.get("id"));
    assertEquals("name", "My Api", elt.get("name"));
}
Also used : Response(javax.ws.rs.core.Response) HashSet(java.util.HashSet) Set(java.util.Set) PolicyEntity(io.gravitee.management.model.PolicyEntity) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with PolicyEntity

use of io.gravitee.management.model.PolicyEntity in project gravitee-management-rest-api by gravitee-io.

the class PoliciesResourceTest method shouldGetPoliciesListWithUnknownExpand.

@Test
public void shouldGetPoliciesListWithUnknownExpand() {
    HashSet<PolicyEntity> policyEntities = new HashSet<>();
    PolicyEntity policyEntity = new PolicyEntity();
    policyEntities.add(policyEntity);
    policyEntity.setId("my-api");
    when(policyService.findAll()).thenReturn(policyEntities);
    final Response response = target().queryParam("expand", "unknown").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Set entity = response.readEntity(Set.class);
    assertFalse("not empty", entity.isEmpty());
    assertEquals("one element", 1, entity.size());
    Object o = entity.iterator().next();
    assertTrue(o instanceof LinkedHashMap);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertEquals("id", "my-api", elt.get("id"));
    assertFalse("unknown expand", elt.containsKey("schema"));
    assertFalse("unknown expand", elt.containsKey("unknown"));
}
Also used : Response(javax.ws.rs.core.Response) HashSet(java.util.HashSet) Set(java.util.Set) PolicyEntity(io.gravitee.management.model.PolicyEntity) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with PolicyEntity

use of io.gravitee.management.model.PolicyEntity in project gravitee-management-rest-api by gravitee-io.

the class PolicyServiceImpl method convert.

private PolicyEntity convert(PolicyPlugin policyPlugin, boolean withPlugin) {
    PolicyEntity entity = new PolicyEntity();
    entity.setId(policyPlugin.id());
    entity.setDescription(policyPlugin.manifest().description());
    entity.setName(policyPlugin.manifest().name());
    entity.setVersion(policyPlugin.manifest().version());
    if (withPlugin) {
        // Plugin information
        Plugin plugin = policyPlugin;
        PluginEntity pluginEntity = new PluginEntity();
        pluginEntity.setPlugin(plugin.clazz());
        pluginEntity.setPath(plugin.path().toString());
        pluginEntity.setType(plugin.type().toString().toLowerCase());
        pluginEntity.setDependencies(plugin.dependencies());
        entity.setPlugin(pluginEntity);
        // Policy development information
        PolicyDevelopmentEntity developmentEntity = new PolicyDevelopmentEntity();
        developmentEntity.setClassName(policyPlugin.policy().getName());
        /*
            if (policy.configuration() != null) {
                developmentEntity.setConfiguration(policyDefinition.configuration().getName());
            }

            if (policyDefinition.onRequestMethod() != null) {
                developmentEntity.setOnRequestMethod(policyDefinition.onRequestMethod().toGenericString());
            }

            if (policyDefinition.onResponseMethod() != null) {
                developmentEntity.setOnResponseMethod(policyDefinition.onResponseMethod().toGenericString());
            }
            */
        entity.setDevelopment(developmentEntity);
    }
    return entity;
}
Also used : PluginEntity(io.gravitee.management.model.PluginEntity) PolicyEntity(io.gravitee.management.model.PolicyEntity) PolicyDevelopmentEntity(io.gravitee.management.model.PolicyDevelopmentEntity) Plugin(io.gravitee.plugin.core.api.Plugin) PolicyPlugin(io.gravitee.plugin.policy.PolicyPlugin)

Example 4 with PolicyEntity

use of io.gravitee.management.model.PolicyEntity in project gravitee-management-rest-api by gravitee-io.

the class PoliciesResourceTest method shouldGetPoliciesListWithSchema.

@Test
public void shouldGetPoliciesListWithSchema() {
    HashSet<PolicyEntity> policyEntities = new HashSet<>();
    PolicyEntity policyEntity = new PolicyEntity();
    policyEntities.add(policyEntity);
    policyEntity.setId("my-api");
    when(policyService.findAll()).thenReturn(policyEntities);
    when(policyService.getSchema(any())).thenReturn("policy schema");
    final Response response = target().queryParam("expand", "schema").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Set entity = response.readEntity(Set.class);
    assertFalse("not empty", entity.isEmpty());
    assertEquals("one element", 1, entity.size());
    Object o = entity.iterator().next();
    assertTrue(o instanceof LinkedHashMap);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertEquals("id", "my-api", elt.get("id"));
    assertEquals("schema", "policy schema", elt.get("schema"));
}
Also used : Response(javax.ws.rs.core.Response) HashSet(java.util.HashSet) Set(java.util.Set) PolicyEntity(io.gravitee.management.model.PolicyEntity) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with PolicyEntity

use of io.gravitee.management.model.PolicyEntity in project gravitee-management-rest-api by gravitee-io.

the class PolicyServiceImpl method findAll.

@Override
public Set<PolicyEntity> findAll() {
    try {
        LOGGER.debug("List all policies");
        final Collection<PolicyPlugin> policyDefinitions = policyManager.findAll();
        return policyDefinitions.stream().map(policyDefinition -> convert(policyDefinition, false)).collect(Collectors.toSet());
    } catch (Exception ex) {
        LOGGER.error("An error occurs while trying to list all policies", ex);
        throw new TechnicalManagementException("An error occurs while trying to list all policies", ex);
    }
}
Also used : PolicyNotFoundException(io.gravitee.management.service.exceptions.PolicyNotFoundException) PolicyService(io.gravitee.management.service.PolicyService) Logger(org.slf4j.Logger) PolicyEntity(io.gravitee.management.model.PolicyEntity) PluginEntity(io.gravitee.management.model.PluginEntity) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PolicyDevelopmentEntity(io.gravitee.management.model.PolicyDevelopmentEntity) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) PolicyPlugin(io.gravitee.plugin.policy.PolicyPlugin) PolicyPluginManager(io.gravitee.plugin.policy.PolicyPluginManager) PolicyPlugin(io.gravitee.plugin.policy.PolicyPlugin) PolicyNotFoundException(io.gravitee.management.service.exceptions.PolicyNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

PolicyEntity (io.gravitee.management.model.PolicyEntity)5 Set (java.util.Set)4 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PluginEntity (io.gravitee.management.model.PluginEntity)2 PolicyDevelopmentEntity (io.gravitee.management.model.PolicyDevelopmentEntity)2 Plugin (io.gravitee.plugin.core.api.Plugin)2 PolicyPlugin (io.gravitee.plugin.policy.PolicyPlugin)2 PolicyService (io.gravitee.management.service.PolicyService)1 PolicyNotFoundException (io.gravitee.management.service.exceptions.PolicyNotFoundException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 PolicyPluginManager (io.gravitee.plugin.policy.PolicyPluginManager)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1