Search in sources :

Example 76 with ConsumerDTO

use of org.candlepin.dto.api.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 77 with ConsumerDTO

use of org.candlepin.dto.api.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 78 with ConsumerDTO

use of org.candlepin.dto.api.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 79 with ConsumerDTO

use of org.candlepin.dto.api.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)

Example 80 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method testUpdateConsumerClearsGuestListWhenRequestGuestListIsEmptyButNotNull.

@Test
public void testUpdateConsumerClearsGuestListWhenRequestGuestListIsEmptyButNotNull() {
    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();
    updated.setGuestIds(new ArrayList<>());
    this.resource.updateConsumer(existing.getUuid(), updated, principal);
    assertTrue(existing.getGuestIds().isEmpty());
}
Also used : Consumer(org.candlepin.model.Consumer) 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 Owner (org.candlepin.model.Owner)20 UserPrincipal (org.candlepin.auth.UserPrincipal)19 HashSet (java.util.HashSet)16 ConsumerType (org.candlepin.model.ConsumerType)16 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)9 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 GuestIdDTO (org.candlepin.dto.api.v1.GuestIdDTO)5