use of org.candlepin.policy.js.compliance.ComplianceStatus in project candlepin by candlepin.
the class ConsumerResourceCreationTest method init.
@Before
public void init() throws Exception {
this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
testMigration = new GuestMigration(consumerCurator);
migrationProvider = Providers.of(testMigration);
this.config = initConfig();
this.resource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, null, null, null, this.userService, null, null, this.ownerCurator, this.activationKeyCurator, null, this.complianceRules, this.deletedConsumerCurator, null, null, this.config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(this.config, this.i18n), null, consumerEnricher, migrationProvider, modelTranslator);
this.system = this.initConsumerType();
this.mockConsumerType(this.system);
this.systemDto = this.modelTranslator.translate(this.system, ConsumerTypeDTO.class);
owner = new Owner("test_owner");
owner.setId(TestUtil.randomString());
user = new User(USER, "");
PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
role = new Role();
role.addPermission(p);
role.addUser(user);
when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(consumerCurator.create(any(Consumer.class), any(Boolean.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
when(userService.findByLogin(USER)).thenReturn(user);
IdentityCertificate cert = new IdentityCertificate();
cert.setKey("testKey");
cert.setCert("testCert");
cert.setId("testId");
cert.setSerial(new CertificateSerial(new Date()));
when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(cert);
when(ownerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
}
use of org.candlepin.policy.js.compliance.ComplianceStatus in project candlepin by candlepin.
the class RulesObjectMapperTest method testComplianceStatusWithSourceConsumerInEnv.
/*
* 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 testComplianceStatusWithSourceConsumerInEnv() {
InputStream is = this.getClass().getResourceAsStream("/json/compliancestatus-with-env.json");
String json = Util.readFile(is);
// Just need this to parse without error:
ComplianceStatus cs = objMapper.toObject(json, ComplianceStatus.class);
}
use of org.candlepin.policy.js.compliance.ComplianceStatus 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));
}
use of org.candlepin.policy.js.compliance.ComplianceStatus in project candlepin by candlepin.
the class ComplianceStatusHasherTest method enssureDifferentHashWhenConsumerInstalledProductsChange.
@Test
public void enssureDifferentHashWhenConsumerInstalledProductsChange() {
Consumer consumer = createConsumer(owner);
Product product = TestUtil.createProduct("Test Product");
ComplianceStatus testStatus = createInitialStatus(consumer);
assertEquals(initialHash, generateHash(testStatus, consumer));
Set<ConsumerInstalledProduct> initialInstalled = consumer.getInstalledProducts();
consumer.setInstalledProducts(new HashSet<>(initialInstalled));
assertEquals(initialHash, generateHash(testStatus, consumer));
consumer.setInstalledProducts(new HashSet<>(initialInstalled));
assertEquals(initialHash, generateHash(testStatus, consumer));
ConsumerInstalledProduct installed = new ConsumerInstalledProduct(product.getUuid(), product.getName());
consumer.addInstalledProduct(installed);
String updatedHash = generateHash(testStatus, consumer);
assertNotEquals(initialHash, updatedHash);
// Test arch change
installed.setArch("test-arch");
assertNotEquals(updatedHash, generateHash(testStatus, consumer));
installed.setArch(null);
assertEquals(updatedHash, generateHash(testStatus, consumer));
// Test version change
installed.setVersion("1.2.3.4");
assertNotEquals(updatedHash, generateHash(testStatus, consumer));
installed.setVersion(null);
assertEquals(updatedHash, generateHash(testStatus, consumer));
consumer.getInstalledProducts().remove(installed);
assertEquals(initialHash, generateHash(testStatus, consumer));
consumer.getInstalledProducts().clear();
assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
use of org.candlepin.policy.js.compliance.ComplianceStatus in project candlepin by candlepin.
the class ComplianceStatusHasherTest method ensureDifferentHashWhenConsumerEntitlementCountsChange.
@Test
public void ensureDifferentHashWhenConsumerEntitlementCountsChange() {
Consumer consumer = createConsumer(owner);
ComplianceStatus testStatus = createInitialStatus(consumer);
assertEquals(initialHash, generateHash(testStatus, consumer));
Set<Entitlement> initialEnts = consumer.getEntitlements();
consumer.setEntitlements(new HashSet<>(initialEnts));
assertEquals(initialHash, generateHash(testStatus, consumer));
// Create and add an entitlement to the consumer.
Entitlement ent = createEntitlement(Calendar.getInstance(), owner, consumer, "tp");
assertNotEquals(initialHash, generateHash(testStatus, consumer));
consumer.removeEntitlement(ent);
assertEquals(initialHash, generateHash(testStatus, consumer));
consumer.getEntitlements().clear();
assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Aggregations