Search in sources :

Example 61 with ConsumerInstalledProduct

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));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Date(java.util.Date) Test(org.junit.Test)

Example 62 with ConsumerInstalledProduct

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());
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) GuestId(org.candlepin.model.GuestId) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) Test(org.junit.Test)

Example 63 with ConsumerInstalledProduct

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;
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerType(org.candlepin.model.ConsumerType)

Example 64 with ConsumerInstalledProduct

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());
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 65 with ConsumerInstalledProduct

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));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Test(org.junit.Test)

Aggregations

ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)66 Consumer (org.candlepin.model.Consumer)54 Product (org.candlepin.model.Product)51 Test (org.junit.Test)49 Owner (org.candlepin.model.Owner)44 Date (java.util.Date)35 DateRange (org.candlepin.policy.js.compliance.DateRange)26 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Entitlement (org.candlepin.model.Entitlement)11 Pool (org.candlepin.model.Pool)11 ConsumerType (org.candlepin.model.ConsumerType)10 AutobindData (org.candlepin.resource.dto.AutobindData)10 HashMap (java.util.HashMap)8 ConsumerCapability (org.candlepin.model.ConsumerCapability)7 List (java.util.List)6 ProductData (org.candlepin.model.dto.ProductData)6 ConsumerInstalledProductDTO (org.candlepin.dto.api.v1.ConsumerInstalledProductDTO)4 Environment (org.candlepin.model.Environment)4 GuestId (org.candlepin.model.GuestId)4