use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method updatedNameRegeneratesIdCert.
@Test
public void updatedNameRegeneratesIdCert() {
ConsumerDTO consumer = getFakeConsumerDTO();
ConsumerDTO updated = new ConsumerDTO();
updated.setName("new name");
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
resource.updateConsumer(consumer.getUuid(), updated, principal);
verify(consumerCurator, times(1)).update(consumerCaptor.capture());
Consumer mergedConsumer = consumerCaptor.getValue();
assertEquals(updated.getName(), mergedConsumer.getName());
assertNotNull(mergedConsumer.getIdCert());
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method canUpdateName.
@Test
public void canUpdateName() {
ConsumerDTO consumer = getFakeConsumerDTO();
ConsumerDTO updated = new ConsumerDTO();
updated.setName("new name");
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
resource.updateConsumer(consumer.getUuid(), updated, principal);
verify(consumerCurator, times(1)).update(consumerCaptor.capture());
Consumer mergedConsumer = consumerCaptor.getValue();
assertEquals(updated.getName(), mergedConsumer.getName());
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method createConsumerDTOWithGuests.
private ConsumerDTO createConsumerDTOWithGuests(String... guestIds) {
Consumer consumer = createConsumerWithGuests(createOwner(), guestIds);
// re-add guestIds as consumer translator removes them.
List<GuestIdDTO> guestIdDTOS = new LinkedList<>();
for (GuestId guestId : consumer.getGuestIds()) {
guestIdDTOS.add(translator.translate(guestId, GuestIdDTO.class));
}
return translator.translate(consumer, ConsumerDTO.class).setGuestIds(guestIdDTOS);
}
use of org.candlepin.dto.api.v1.ConsumerDTO 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.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method ensureEventIsNotFiredWhenNoChangeWasMadeToConsumerGuestIds.
@Test
public void ensureEventIsNotFiredWhenNoChangeWasMadeToConsumerGuestIds() {
String uuid = "TEST_CONSUMER";
Consumer existing = createConsumerWithGuests(createOwner(), "Guest 1", "Guest 2");
existing.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
ConsumerDTO updated = createConsumerDTOWithGuests("Guest 1", "Guest 2");
updated.setUuid(uuid);
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(new VirtConsumerMap());
this.resource.updateConsumer(existing.getUuid(), updated, principal);
verify(sink, never()).queueEvent(any(Event.class));
}
Aggregations