Search in sources :

Example 1 with PolicyCacheConfiguration

use of com.walmartlabs.concord.server.cfg.PolicyCacheConfiguration in project concord by walmartlabs.

the class PolicyCacheTest method allowNullValues.

@Test
public void allowNullValues() {
    PolicyCache.Dao dao = mock(PolicyCache.Dao.class);
    PolicyCache pc = new PolicyCache(TestObjectMapper.INSTANCE, new PolicyCacheConfiguration(), dao);
    // ---
    Map<String, Object> ruleParams = new HashMap<>();
    ruleParams.put("nullValue", null);
    ruleParams.put("nullValue2", null);
    Map<String, Object> conditions = Collections.singletonMap("entity", ImmutableMap.of("params", ruleParams));
    Map<String, Object> denyEntityRule = new HashMap<>();
    denyEntityRule.put("msg", "test message");
    denyEntityRule.put("action", "create");
    denyEntityRule.put("entity", "trigger");
    denyEntityRule.put("conditions", conditions);
    Map<String, Object> rules = new HashMap<>();
    rules.put("entity", Collections.singletonMap("deny", Collections.singletonList(denyEntityRule)));
    List<PolicyCache.PolicyRules> policies = Collections.singletonList(PolicyCache.PolicyRules.builder().id(UUID.randomUUID()).name("test").rules(rules).build());
    // ---
    Map<UUID, PolicyCache.Policy> merged = pc.mergePolicies(policies);
    assertEquals(1, merged.size());
    PolicyEngineRules actualRules = merged.values().iterator().next().rules();
    assertEquals(1, actualRules.getEntityRules().getDeny().size());
    EntityRule actualRule = actualRules.getEntityRules().getDeny().get(0);
    assertEquals(conditions, actualRule.getConditions());
}
Also used : PolicyCacheConfiguration(com.walmartlabs.concord.server.cfg.PolicyCacheConfiguration) EntityRule(com.walmartlabs.concord.policyengine.EntityRule) PolicyEngineRules(com.walmartlabs.concord.policyengine.PolicyEngineRules) Test(org.junit.jupiter.api.Test)

Aggregations

EntityRule (com.walmartlabs.concord.policyengine.EntityRule)1 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)1 PolicyCacheConfiguration (com.walmartlabs.concord.server.cfg.PolicyCacheConfiguration)1 Test (org.junit.jupiter.api.Test)1