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