use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method ensureGuestEntitlementsUntouchedWhenGuestIsNewWithNoOtherHost.
@Test
public void ensureGuestEntitlementsUntouchedWhenGuestIsNewWithNoOtherHost() {
String uuid = "TEST_CONSUMER";
Consumer host = createConsumerWithGuests(createOwner());
host.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
updatedHost.setUuid(uuid);
Entitlement entitlement = TestUtil.createEntitlement();
entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
Consumer guest1 = new Consumer();
guest1.setUuid("Guest 1");
guest1.addEntitlement(entitlement);
guest1.setAutoheal(true);
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
// Ensure that the guest was not reported by another host.
when(this.consumerCurator.find(eq(guest1.getId()))).thenReturn(guest1);
this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method consumerLastCheckin.
@Test
public void consumerLastCheckin() {
ConsumerType ct = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
this.mockConsumerType(ct);
Consumer c = getFakeConsumer();
Date now = new Date();
c.setLastCheckin(now);
c.setType(ct);
when(this.consumerCurator.verifyAndLookupConsumer(c.getUuid())).thenReturn(c);
ConsumerDTO updated = new ConsumerDTO();
Date then = new Date(now.getTime() + 10000L);
updated.setLastCheckin(then);
resource.updateConsumer(c.getUuid(), updated, principal);
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method testUpdateConsumerDoesNotChangeGuestsWhenGuestIdsNotIncludedInRequest.
@Test
public void testUpdateConsumerDoesNotChangeGuestsWhenGuestIdsNotIncludedInRequest() {
String uuid = "TEST_CONSUMER";
String[] guests = new String[] { "Guest 1", "Guest 2" };
Consumer existing = createConsumerWithGuests(createOwner(), guests);
existing.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
ConsumerDTO updated = new ConsumerDTO();
this.resource.updateConsumer(existing.getUuid(), updated, principal);
assertEquals(guests.length, existing.getGuestIds().size());
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method ensureGuestEntitlementsUntouchedWhenGuestExistsWithNoOtherHost.
@Test
public void ensureGuestEntitlementsUntouchedWhenGuestExistsWithNoOtherHost() {
String uuid = "TEST_CONSUMER";
Consumer host = createConsumerWithGuests(createOwner(), "Guest 1");
host.setUuid(uuid);
when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
updatedHost.setUuid(uuid);
Entitlement entitlement = TestUtil.createEntitlement();
entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
Consumer guest1 = new Consumer();
guest1.setUuid("Guest 1");
guest1.addEntitlement(entitlement);
// Ensure that the guest was already reported by same host.
when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
use of org.candlepin.dto.rules.v1.ConsumerDTO 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());
}
Aggregations