Search in sources :

Example 21 with ConsumerDTO

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

Example 22 with ConsumerDTO

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

Example 23 with ConsumerDTO

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());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 24 with ConsumerDTO

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

Example 25 with ConsumerDTO

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

Aggregations

Test (org.junit.Test)70 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)64 Consumer (org.candlepin.model.Consumer)37 UserPrincipal (org.candlepin.auth.UserPrincipal)19 Owner (org.candlepin.model.Owner)19 ConsumerType (org.candlepin.model.ConsumerType)16 HashSet (java.util.HashSet)15 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)15 Principal (org.candlepin.auth.Principal)14 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)13 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)12 Set (java.util.Set)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)8 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)7 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Entitlement (org.candlepin.model.Entitlement)5