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());
}
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;
}
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));
}
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());
}
Aggregations