Search in sources :

Example 26 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method updatingToNullNameIgnoresName.

@Test
public void updatingToNullNameIgnoresName() {
    ConsumerDTO consumer = getFakeConsumerDTO();
    consumer.setName("old name");
    ConsumerDTO updated = new ConsumerDTO();
    updated.setName(null);
    resource.updateConsumer(consumer.getUuid(), updated, principal);
    assertEquals("old name", consumer.getName());
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 27 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method guestEntitlementsNotRemovedIfEntitlementIsVirtOnlyButRequiresHostNotSet.

@Test
public void guestEntitlementsNotRemovedIfEntitlementIsVirtOnlyButRequiresHostNotSet() {
    String uuid = "TEST_CONSUMER";
    Consumer host = createConsumerWithGuests(createOwner(), "Guest 1", "Guest 2");
    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");
    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));
    when(this.consumerCurator.find(eq(guest1.getId()))).thenReturn(guest1);
    this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
    // verify(consumerCurator).findByVirtUuid(eq("Guest 1"));
    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 28 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method updatingToInvalidCharacterNameNotAllowed.

@Test(expected = BadRequestException.class)
public void updatingToInvalidCharacterNameNotAllowed() {
    ConsumerDTO consumer = getFakeConsumerDTO();
    consumer.setName("old name");
    ConsumerDTO updated = new ConsumerDTO();
    updated.setName("#a name");
    resource.updateConsumer(consumer.getUuid(), updated, principal);
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 29 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method ensureEventIsNotFiredWhenGuestIDCaseChanges.

@Test
public void ensureEventIsNotFiredWhenGuestIDCaseChanges() {
    String uuid = "TEST_CONSUMER";
    Consumer existing = createConsumerWithGuests(createOwner(), "aaa123", "bbb123");
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    // flip case on one ID, should be treated as no change
    ConsumerDTO updated = createConsumerDTOWithGuests("aaa123", "BBB123");
    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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Event(org.candlepin.audit.Event) Test(org.junit.Test)

Example 30 with ConsumerDTO

use of org.candlepin.dto.manifest.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testFetchAllConsumersForOwner.

public void testFetchAllConsumersForOwner() {
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    ArrayList<Consumer> consumers = new ArrayList<>();
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(consumers);
    when(cqmock.iterator()).thenReturn(consumers.iterator());
    when(mockOwnerCurator.lookupByKey(eq("taylorOwner"))).thenReturn(new Owner());
    when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
    List<ConsumerDTO> result = cr.list(null, null, "taylorOwner", null, null, null, null).list();
    assertEquals(consumers, result);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) ArrayList(java.util.ArrayList) List(java.util.List) ConsumerType(org.candlepin.model.ConsumerType)

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