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