Search in sources :

Example 6 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenReasonKeyChange.

@Test
public void ensureDifferentHashWhenReasonKeyChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    ComplianceReason reason = testStatus.getReasons().iterator().next();
    reason.setKey("FOOF");
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason) Test(org.junit.Test)

Example 7 with ComplianceStatus

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

the class ComplianceStatusHasherTest method createInitialStatus.

private ComplianceStatus createInitialStatus(Consumer consumer) {
    // Need to make sure that dates are exactly the same
    // as this method will be called more than once.
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2001);
    cal.set(Calendar.MONTH, 4);
    cal.set(Calendar.DATE, 12);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    ComplianceStatus initialStatus = new ComplianceStatus(cal.getTime());
    addMonths(cal, 4);
    initialStatus.addNonCompliantProduct("p1");
    initialStatus.addNonCompliantProduct("p2");
    initialStatus.addCompliantProduct("p3", createEntitlement(cal, owner, consumer, "p3"));
    initialStatus.addCompliantProduct("p4", createEntitlement(cal, owner, consumer, "p4"));
    initialStatus.addPartiallyCompliantProduct("p5", createEntitlement(cal, owner, consumer, "p5"));
    initialStatus.addPartialStack("p-stack", createEntitlement(cal, owner, consumer, "p6"));
    ComplianceReason reason1 = createReason("TEST-REASON-1");
    initialStatus.getReasons().add(reason1);
    ComplianceReason reason2 = createReason("TEST-REASON-2");
    initialStatus.getReasons().add(reason2);
    return initialStatus;
}
Also used : ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Calendar(java.util.Calendar) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason)

Example 8 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenConsumerEntitlementChanges.

@Test
public void ensureDifferentHashWhenConsumerEntitlementChanges() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Entitlement ent = consumer.getEntitlements().iterator().next();
    String id = ent.getId();
    Integer quantity = ent.getQuantity();
    // Check the ID
    ent.setId("somethhing_differerent");
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    ent.setId(id);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    // Check the quantity
    ent.setQuantity(112);
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    ent.setQuantity(quantity);
    assertEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 9 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenNonCompliantProductsChange.

@Test
public void ensureDifferentHashWhenNonCompliantProductsChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    testStatus.getNonCompliantProducts().clear();
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    testStatus.addNonCompliantProduct("p1");
    testStatus.addNonCompliantProduct("p2");
    assertEquals(initialHash, generateHash(testStatus, consumer));
    assertTrue(testStatus.getNonCompliantProducts().remove("p1"));
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Test(org.junit.Test)

Example 10 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenPartiallyCompliantProductsChange.

@Test
public void ensureDifferentHashWhenPartiallyCompliantProductsChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Entitlement ent = createEntitlement(Calendar.getInstance(), owner, consumer, "test-ent");
    HashSet<Entitlement> ents = new HashSet<>();
    ents.add(ent);
    testStatus.getPartiallyCompliantProducts().put(ent.getPool().getProductId(), ents);
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ComplianceStatus (org.candlepin.policy.js.compliance.ComplianceStatus)32 Consumer (org.candlepin.model.Consumer)26 Test (org.junit.Test)21 Date (java.util.Date)13 Entitlement (org.candlepin.model.Entitlement)8 HashSet (java.util.HashSet)7 ConsumerType (org.candlepin.model.ConsumerType)7 HashMap (java.util.HashMap)6 Owner (org.candlepin.model.Owner)5 Product (org.candlepin.model.Product)5 Before (org.junit.Before)5 StandardTranslator (org.candlepin.dto.StandardTranslator)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4 Pool (org.candlepin.model.Pool)4 ComplianceReason (org.candlepin.policy.js.compliance.ComplianceReason)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Set (java.util.Set)3 Target (org.candlepin.audit.Event.Target)3 Type (org.candlepin.audit.Event.Type)3