use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method setStatusOnUpdate.
@Test
public void setStatusOnUpdate() throws Exception {
Product productA = TestUtil.createProduct("Product A");
Product productB = TestUtil.createProduct("Product B");
Product productC = TestUtil.createProduct("Product C");
Consumer consumer = getFakeConsumer();
consumer.addInstalledProduct(new ConsumerInstalledProduct(consumer, productA));
consumer.addInstalledProduct(new ConsumerInstalledProduct(consumer, productB));
ConsumerDTO incoming = new ConsumerDTO();
incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productB.getId(), productB.getName()));
incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productC.getId(), productC.getName()));
this.resource.updateConsumer(consumer.getUuid(), incoming, principal);
verify(sink).queueEvent((Event) any());
verify(complianceRules).getStatus(eq(consumer), any(Date.class), any(Boolean.class), any(Boolean.class));
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method multipleUpdatesCanOccur.
@Test
public void multipleUpdatesCanOccur() {
String uuid = "A Consumer";
String expectedFactName = "FACT1";
String expectedFactValue = "F1";
GuestIdDTO expectedGuestId = TestUtil.createGuestIdDTO("GUEST_ID_1");
Consumer existing = getFakeConsumer();
existing.setFacts(new HashMap<>());
existing.setInstalledProducts(new HashSet<>());
ConsumerDTO updated = new ConsumerDTO();
updated.setUuid(uuid);
updated.setFact(expectedFactName, expectedFactValue);
Product prod = TestUtil.createProduct("Product One");
ConsumerInstalledProductDTO expectedInstalledProduct = new ConsumerInstalledProductDTO(prod.getId(), prod.getName());
updated.addInstalledProduct(expectedInstalledProduct);
updated.addGuestId(expectedGuestId);
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
this.resource.updateConsumer(existing.getUuid(), updated, principal);
assertEquals(1, existing.getFacts().size());
assertEquals(expectedFactValue, existing.getFact(expectedFactName));
assertEquals(1, existing.getInstalledProducts().size());
ConsumerInstalledProduct actualCIP = existing.getInstalledProducts().iterator().next();
assertNotNull(actualCIP);
assertEquals(actualCIP.getProductId(), expectedInstalledProduct.getProductId());
assertEquals(actualCIP.getProductName(), expectedInstalledProduct.getProductName());
assertEquals(actualCIP.getVersion(), expectedInstalledProduct.getVersion());
assertEquals(actualCIP.getArch(), expectedInstalledProduct.getArch());
assertEquals(actualCIP.getStatus(), expectedInstalledProduct.getStatus());
assertEquals(actualCIP.getStartDate(), expectedInstalledProduct.getStartDate());
assertEquals(actualCIP.getEndDate(), expectedInstalledProduct.getEndDate());
assertEquals(1, existing.getGuestIds().size());
GuestId actualGID = existing.getGuestIds().iterator().next();
assertNotNull(actualGID);
assertEquals(actualGID.getGuestId(), expectedGuestId.getGuestId());
assertEquals(actualGID.getAttributes(), expectedGuestId.getAttributes());
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class ComplianceRulesTest method mockConsumer.
private Consumer mockConsumer(Product... installedProducts) {
ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype-" + TestUtil.randomInt());
Consumer consumer = new Consumer();
consumer.setType(ctype);
when(this.consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(this.consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
for (Product product : installedProducts) {
consumer.addInstalledProduct(new ConsumerInstalledProduct(product.getId(), product.getName()));
}
// 8 socket machine
consumer.setFact("cpu.cpu_socket(s)", "8");
return consumer;
}
use of org.candlepin.model.ConsumerInstalledProduct in project candlepin by candlepin.
the class StatusReasonMessageGeneratorTest method testNonInstalled.
@Test
public void testNonInstalled() {
HashMap<String, String> attrs = new HashMap<>();
attrs.put("product_id", "prod1");
ComplianceReason reason = buildReason("NOTCOVERED", attrs);
Owner owner = new Owner("test");
Product product = TestUtil.createProduct("prod1", "NonCovered Product");
ConsumerInstalledProduct installed = new ConsumerInstalledProduct(product.getId(), product.getName());
consumer.addInstalledProduct(installed);
generator.setMessage(consumer, reason, new Date());
assertEquals("Not supported by a valid subscription.", reason.getMessage());
}
use of org.candlepin.model.ConsumerInstalledProduct 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));
}
Aggregations