Search in sources :

Example 1 with ConsumerInstalledProductDTO

use of org.candlepin.dto.api.v1.ConsumerInstalledProductDTO in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method installedPackagesChanged.

@Test
public void installedPackagesChanged() 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(productA));
    consumer.addInstalledProduct(new ConsumerInstalledProduct(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());
}
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) Test(org.junit.Test)

Example 2 with ConsumerInstalledProductDTO

use of org.candlepin.dto.api.v1.ConsumerInstalledProductDTO in project candlepin by candlepin.

the class ConsumerResource method populateInstalledProducts.

/**
 * Utility method that translates a ConsumerDTO's installed products to
 * Consumer model entity installed products.
 *
 * @param entity the Consumer model entity which the installed products are to reference
 *
 * @param dto the ConsumerDTO whose installed products we want to translate
 *
 * @return the model entity ConsumerInstalledProduct set that was created
 */
private Set<ConsumerInstalledProduct> populateInstalledProducts(Consumer entity, ConsumerDTO dto) {
    Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
    for (ConsumerInstalledProductDTO installedProductDTO : dto.getInstalledProducts()) {
        if (installedProductDTO != null) {
            ConsumerInstalledProduct installedProduct = new ConsumerInstalledProduct(installedProductDTO.getProductId(), installedProductDTO.getProductName(), entity, installedProductDTO.getVersion(), installedProductDTO.getArch(), installedProductDTO.getStatus(), installedProductDTO.getStartDate(), installedProductDTO.getEndDate());
            installedProducts.add(installedProduct);
        }
    }
    return installedProducts;
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 3 with ConsumerInstalledProductDTO

use of org.candlepin.dto.api.v1.ConsumerInstalledProductDTO 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 4 with ConsumerInstalledProductDTO

use of org.candlepin.dto.api.v1.ConsumerInstalledProductDTO 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)

Aggregations

ConsumerInstalledProductDTO (org.candlepin.dto.api.v1.ConsumerInstalledProductDTO)4 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)4 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)3 Consumer (org.candlepin.model.Consumer)3 Product (org.candlepin.model.Product)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 Date (java.util.Date)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)1 GuestId (org.candlepin.model.GuestId)1 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)1 Mockito.anyBoolean (org.mockito.Mockito.anyBoolean)1