Search in sources :

Example 71 with ConsumerDTO

use of org.candlepin.dto.rules.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));
}
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 72 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method throwsAnExceptionWhenEnvironmentNotFound.

@Test(expected = NotFoundException.class)
public void throwsAnExceptionWhenEnvironmentNotFound() {
    String uuid = "A Consumer";
    EnvironmentDTO changedEnvironment = new EnvironmentDTO().setId("42").setName("environment");
    ConsumerDTO updated = new ConsumerDTO();
    updated.setUuid(uuid);
    updated.setEnvironment(changedEnvironment);
    Consumer existing = getFakeConsumer();
    existing.setUuid(updated.getUuid());
    when(consumerCurator.verifyAndLookupConsumer(existing.getUuid())).thenReturn(existing);
    when(environmentCurator.find(changedEnvironment.getId())).thenReturn(null);
    resource.updateConsumer(existing.getUuid(), updated, principal);
}
Also used : Consumer(org.candlepin.model.Consumer) EnvironmentDTO(org.candlepin.dto.api.v1.EnvironmentDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 73 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method testUpdateConsumerUpdatesGuestIds.

@Test
public void testUpdateConsumerUpdatesGuestIds() {
    String uuid = "TEST_CONSUMER";
    String[] existingGuests = new String[] { "Guest 1", "Guest 2", "Guest 3" };
    Consumer existing = createConsumerWithGuests(createOwner(), existingGuests);
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    ConsumerDTO updated = new ConsumerDTO();
    updated.setUuid(uuid);
    GuestIdDTO expectedGuestId = TestUtil.createGuestIdDTO("Guest 2");
    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.getGuestIds().size());
    GuestId actualGID = existing.getGuestIds().iterator().next();
    assertNotNull(actualGID);
    assertEquals(actualGID.getGuestId(), expectedGuestId.getGuestId());
    assertEquals(actualGID.getAttributes(), expectedGuestId.getAttributes());
}
Also used : GuestIdDTO(org.candlepin.dto.api.v1.GuestIdDTO) Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) GuestId(org.candlepin.model.GuestId) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 74 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method nullReleaseVer.

@Test
public void nullReleaseVer() {
    ConsumerDTO consumer = getFakeConsumerDTO();
    consumer.setReleaseVersion(null);
    ConsumerDTO incoming = new ConsumerDTO();
    incoming.setReleaseVersion("not null");
    this.resource.updateConsumer(consumer.getUuid(), incoming, principal);
    ConsumerDTO consumer2 = getFakeConsumerDTO();
    consumer2.setReleaseVersion("foo");
    ConsumerDTO incoming2 = new ConsumerDTO();
    incoming2.setReleaseVersion(null);
    this.resource.updateConsumer(consumer2.getUuid(), incoming2, principal);
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 75 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method sameNameDoesntRegenIdCert.

@Test
public void sameNameDoesntRegenIdCert() {
    ConsumerDTO consumer = getFakeConsumerDTO();
    consumer.setName("old name");
    ConsumerDTO updated = new ConsumerDTO();
    updated.setName("old name");
    resource.updateConsumer(consumer.getUuid(), updated, principal);
    assertEquals(updated.getName(), consumer.getName());
    assertNull(consumer.getIdCert());
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) 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