use of io.gravitee.definition.model.flow.Step in project gravitee-management-rest-api by gravitee-io.
the class PolicyServiceTest method shouldAcceptValidJsonConfigurationWithNoSchemaStep.
@Test
public void shouldAcceptValidJsonConfigurationWithNoSchemaStep() throws Exception {
Step step = new Step();
step.setPolicy("my-policy");
step.setConfiguration("{ \"name\": \"test\", \"valid\": true }");
when(policyManager.getSchema("my-policy")).thenReturn("");
policyService.validatePolicyConfiguration(step);
}
use of io.gravitee.definition.model.flow.Step in project gravitee-management-rest-api by gravitee-io.
the class PolicyServiceTest method shouldRejectInvalidJsonStep.
@Test(expected = InvalidDataException.class)
public void shouldRejectInvalidJsonStep() throws Exception {
Step step = new Step();
step.setPolicy("my-policy");
step.setConfiguration("{ Invalid: \"test\", \"valid\": false }");
policyService.validatePolicyConfiguration(step);
}
use of io.gravitee.definition.model.flow.Step in project gravitee-management-rest-api by gravitee-io.
the class PolicyServiceTest method shouldAcceptNoConfigurationStep.
@Test
public void shouldAcceptNoConfigurationStep() {
Step step = new Step();
step.setPolicy("my-policy");
step.setConfiguration(null);
policyService.validatePolicyConfiguration(step);
}
use of io.gravitee.definition.model.flow.Step in project gravitee-management-rest-api by gravitee-io.
the class APIV1toAPIV2Converter method configurePolicies.
/**
* Configure Flow's Steps from Rule.
* @param policies, the list of available policies, containing available scopes
* @param rule, the rule to transform into Step
* @param flow, the current Flow
*/
private void configurePolicies(Set<PolicyEntity> policies, Rule rule, Flow flow) {
policies.stream().filter(policy -> policy.getId().equals(rule.getPolicy().getName())).findFirst().ifPresent(policy -> {
String rulePolicyConfiguration = rule.getPolicy().getConfiguration();
String safeRulePolicyConfiguration = clearNullValues(rulePolicyConfiguration);
if (policy.getDevelopment().getOnRequestMethod() != null && policy.getDevelopment().getOnResponseMethod() != null) {
try {
JsonNode jsonRulePolicyConfiguration = JsonLoader.fromString(safeRulePolicyConfiguration);
JsonNode scope = jsonRulePolicyConfiguration.get("scope");
if (scope != null) {
switch(scope.asText()) {
case "REQUEST":
case "REQUEST_CONTENT":
{
final Step step = createStep(rule, policy, safeRulePolicyConfiguration);
flow.getPre().add(step);
break;
}
case "RESPONSE":
case "RESPONSE_CONTENT":
{
final Step step = createStep(rule, policy, safeRulePolicyConfiguration);
flow.getPost().add(step);
break;
}
}
}
} catch (IOException e) {
throw new InvalidDataException("Unable to validate policy configuration", e);
}
} else if (policy.getDevelopment().getOnRequestMethod() != null) {
final Step step = createStep(rule, policy, safeRulePolicyConfiguration);
flow.getPre().add(step);
} else if (policy.getDevelopment().getOnResponseMethod() != null) {
final Step step = createStep(rule, policy, safeRulePolicyConfiguration);
flow.getPost().add(step);
}
});
}
use of io.gravitee.definition.model.flow.Step in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_CreateAPIV2Test method validateRules.
@Override
protected void validateRules(SwaggerApiEntity api, String path, int expectedRuleSize, List<HttpMethod> firstRuleMethods, String firstRuleDescription) {
List<Flow> flows = api.getFlows().stream().filter(flow1 -> flow1.getPath().equals(path)).collect(Collectors.toList());
// assertEquals(1, flows.size());
assertEquals(expectedRuleSize, flows.get(0).getPre().size());
assertTrue(flows.get(0).getMethods().containsAll(firstRuleMethods));
Step step = flows.get(0).getPre().get(0);
assertNotNull(step);
assertEquals(firstRuleDescription, step.getDescription());
}
Aggregations