use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeCorrectPartialEntitlementNoGap.
@Test
public void validRangeCorrectPartialEntitlementNoGap() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
DateRange range2 = this.rangeRelativeToDate(now, 4, 9);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range1.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class InstalledProductStatusCalculatorTest method validRangeEndDateSetToFirstDateOfLosingValidStatus.
@Test
public void validRangeEndDateSetToFirstDateOfLosingValidStatus() {
Date now = new Date();
Owner owner = TestUtil.createOwner();
Product product = TestUtil.createProduct("p1", "product1");
Consumer consumer = this.mockConsumer(owner, product);
consumer.setCreated(now);
DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
DateRange range2 = this.rangeRelativeToDate(now, -2, 10);
DateRange range3 = this.rangeRelativeToDate(now, -3, -1);
DateRange range4 = this.rangeRelativeToDate(range1.getEndDate(), 0, 10);
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range3, product));
consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range4, product));
this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
this.mockOwnerProducts(owner, Arrays.asList(product));
this.consumerEnricher.enrich(consumer);
ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
assertEquals(range3.getStartDate(), cip.getStartDate());
assertEquals(range2.getEndDate(), cip.getEndDate());
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsAutoAttach.
@Test
public void registerWithKeyWithInstalledProductsAutoAttach() throws Exception {
Product prod = TestUtil.createProduct();
String[] prodIds = new String[] { prod.getId() };
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
key1.setAutoAttach(true);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
Set<ConsumerInstalledProduct> cips = new HashSet<>();
ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod);
cips.add(cip);
consumer.setInstalledProducts(cips);
AutobindData ad = new AutobindData(consumer, owner).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsPlusAutoAttach.
@Test
public void registerWithKeyWithInstalledProductsPlusAutoAttach() throws Exception {
// installed product
Product prod1 = TestUtil.createProduct();
// key product
Product prod2 = TestUtil.createProduct();
String[] prodIds = new String[] { prod1.getId(), prod2.getId() };
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
key1.addProduct(prod2);
key1.setAutoAttach(true);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
Set<ConsumerInstalledProduct> cips = new HashSet<>();
ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod1);
cips.add(cip);
consumer.setInstalledProducts(cips);
AutobindData ad = new AutobindData(consumer, owner).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Consumer source, ConsumerDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dest.getId());
assertEquals(source.getUuid(), dest.getUuid());
assertEquals(source.getName(), dest.getName());
assertEquals(source.getUsername(), dest.getUsername());
assertEquals(source.getEntitlementStatus(), dest.getEntitlementStatus());
assertEquals(source.getServiceLevel(), dest.getServiceLevel());
assertEquals(source.getEntitlementCount(), (long) dest.getEntitlementCount());
assertEquals(source.getFacts(), dest.getFacts());
assertEquals(source.getLastCheckin(), dest.getLastCheckin());
assertEquals(source.isCanActivate(), dest.isCanActivate());
assertEquals(source.getContentTags(), dest.getContentTags());
assertEquals(source.isAutoheal(), dest.getAutoheal());
assertEquals(source.getRecipientOwnerKey(), dest.getRecipientOwnerKey());
assertEquals(source.getAnnotations(), dest.getAnnotations());
assertEquals(source.getContentAccessMode(), dest.getContentAccessMode());
if (childrenGenerated) {
ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
Environment environment = this.mockEnvironmentCurator.getConsumerEnvironment(source);
this.environmentTranslatorTest.verifyOutput(environment, dest.getEnvironment(), true);
assertEquals(source.getReleaseVer().getReleaseVer(), dest.getReleaseVersion());
String destOwnerId = null;
if (dest.getOwner() != null) {
destOwnerId = dest.getOwner().getId();
}
assertEquals(source.getOwnerId(), destOwnerId);
this.hypervisorIdTranslatorTest.verifyOutput(source.getHypervisorId(), dest.getHypervisorId(), childrenGenerated);
this.certificateTranslatorTest.verifyOutput(source.getIdCert(), dest.getIdCert(), true);
if (source.getInstalledProducts() != null) {
for (ConsumerInstalledProduct cip : source.getInstalledProducts()) {
for (ConsumerInstalledProductDTO cipDTO : dest.getInstalledProducts()) {
assertNotNull(cip);
assertNotNull(cipDTO);
this.cipTranslatorTest.verifyOutput(cip, cipDTO, childrenGenerated);
}
}
} else {
assertNull(dest.getInstalledProducts());
}
if (source.getCapabilities() != null) {
for (ConsumerCapability cc : source.getCapabilities()) {
boolean verified = false;
for (CapabilityDTO ccDTO : dest.getCapabilities()) {
assertNotNull(cc);
assertNotNull(ccDTO);
if (cc.getName().contentEquals(ccDTO.getName())) {
this.capabilityTranslatorTest.verifyOutput(cc, ccDTO, childrenGenerated);
verified = true;
}
}
assertTrue(verified);
}
} else {
assertNull(dest.getCapabilities());
}
assertEquals(0, dest.getGuestIds().size());
} else {
assertNull(dest.getReleaseVersion());
assertNull(dest.getOwner());
assertNull(dest.getEnvironment());
assertNull(dest.getHypervisorId());
assertNull(dest.getType());
assertNull(dest.getIdCert());
assertNull(dest.getInstalledProducts());
assertNull(dest.getCapabilities());
assertNull(dest.getGuestIds());
}
} else {
assertNull(dest);
}
}
Aggregations