Search in sources :

Example 11 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenPartialStacksChange.

@Test
public void ensureDifferentHashWhenPartialStacksChange() {
    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.getPartialStacks().put("p-stack-2", 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)

Example 12 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenCompliantProductCountChanges.

@Test
public void ensureDifferentHashWhenCompliantProductCountChanges() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Set<Entitlement> ents = testStatus.getCompliantProducts().remove("p3");
    assertFalse(testStatus.getCompliantProducts().containsKey("p3"));
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    testStatus.getCompliantProducts().put("p3", ents);
    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 13 with ComplianceStatus

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

the class ComplianceStatusHasherTest method ensureDifferentHashWhenReasonsChange.

@Test
public void ensureDifferentHashWhenReasonsChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    ComplianceReason reason = new ComplianceReason();
    reason.setKey("TEST-REASON-KEY");
    reason.setMessage("This is a test!");
    testStatus.getReasons().add(reason);
    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 14 with ComplianceStatus

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

the class RulesObjectMapperTest method testComplianceStatusWithSourceConsumerInEnvV2.

/*
     * Tests a bug found where consumer environment content is serialized without
     * an environment (as it would be a circular dep), resulting in a null environment
     * on the object and a very upset hashCode method.
     */
@Test
public void testComplianceStatusWithSourceConsumerInEnvV2() {
    InputStream is = this.getClass().getResourceAsStream("/json/compliancestatus-with-env-v2.json");
    String json = Util.readFile(is);
    // Just need this to parse without error:
    ComplianceStatus cs = objMapper.toObject(json, ComplianceStatus.class);
}
Also used : ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 15 with ComplianceStatus

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

the class ConsumerResourceTest method testIdCertGetsRegenerated.

@Test
public void testIdCertGetsRegenerated() throws Exception {
    // using lconsumer simply to avoid hiding consumer. This should
    // get renamed once we refactor this test suite.
    IdentityCertServiceAdapter mockIdSvc = Mockito.mock(IdentityCertServiceAdapter.class);
    EventSink sink = Mockito.mock(EventSinkImpl.class);
    SubscriptionServiceAdapter ssa = Mockito.mock(SubscriptionServiceAdapter.class);
    ComplianceRules rules = Mockito.mock(ComplianceRules.class);
    Consumer consumer = createConsumer(createOwner());
    ComplianceStatus status = new ComplianceStatus();
    when(rules.getStatus(any(Consumer.class), any(Date.class), anyBoolean())).thenReturn(status);
    // cert expires today which will trigger regen
    consumer.setIdCert(createIdCert());
    BigInteger origserial = consumer.getIdCert().getSerial().getSerial();
    when(mockIdSvc.regenerateIdentityCert(consumer)).thenReturn(createIdCert());
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, ssa, this.mockOwnerServiceAdapter, null, mockIdSvc, null, null, sink, eventFactory, null, null, null, null, null, mockOwnerCurator, null, null, rules, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    ConsumerDTO c = cr.getConsumer(consumer.getUuid());
    assertFalse(origserial.equals(c.getIdCert().getSerial().getSerial()));
}
Also used : IdentityCertServiceAdapter(org.candlepin.service.IdentityCertServiceAdapter) Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) BigInteger(java.math.BigInteger) EventSink(org.candlepin.audit.EventSink) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Date(java.util.Date) 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