Search in sources :

Example 6 with ComplianceReason

use of org.candlepin.policy.js.compliance.ComplianceReason in project candlepin by candlepin.

the class ComplianceStatusHasherTest method ensureDifferentHashWhenReasonAttributeChanges.

@Test
public void ensureDifferentHashWhenReasonAttributeChanges() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    ComplianceReason reason = testStatus.getReasons().iterator().next();
    // Test new attribute map same values
    Map<String, String> newAttrs = new HashMap<>();
    newAttrs.putAll(reason.getAttributes());
    reason.setAttributes(newAttrs);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    // Test new value
    newAttrs.put(reason.getKey() + "-attr", reason.getKey() + "-value");
    assertEquals(initialHash, generateHash(testStatus, consumer));
    newAttrs.put(reason.getKey() + "-attr", "new value");
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    // Test new attribute.
    newAttrs.put("test-key", "test-value");
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    // Test attribute count.
    newAttrs.clear();
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) HashMap(java.util.HashMap) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason) Test(org.junit.Test)

Example 7 with ComplianceReason

use of org.candlepin.policy.js.compliance.ComplianceReason in project candlepin by candlepin.

the class ComplianceStatusHasherTest method createReason.

private ComplianceReason createReason(String key) {
    ComplianceReason reason = new ComplianceReason();
    reason.setKey(key);
    reason.setMessage(key + ": This is a test!");
    Map<String, String> attrs = new HashMap<>();
    attrs.put(key + "-attr", key + "-value");
    reason.setAttributes(attrs);
    return reason;
}
Also used : HashMap(java.util.HashMap) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason)

Aggregations

ComplianceReason (org.candlepin.policy.js.compliance.ComplianceReason)7 ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)5 Consumer (org.candlepin.model.Consumer)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 IseException (org.candlepin.common.exceptions.IseException)1