use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testCreateConsumerWithUUID.
@Test(expected = BadRequestException.class)
public void testCreateConsumerWithUUID() {
String uuid = "Jar Jar Binks";
ConsumerDTO toSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
assertNull(toSubmit.getId());
toSubmit.setUuid(uuid);
toSubmit.setFact(METADATA_NAME, METADATA_VALUE);
ConsumerDTO submitted = consumerResource.create(toSubmit, principal, null, owner.getKey(), null, true);
assertNotNull(submitted);
assertNotNull(submitted.getId());
assertNotNull(consumerCurator.find(submitted.getId()));
assertNotNull(consumerCurator.findByUuid(uuid));
assertEquals(standardSystemType.getLabel(), submitted.getType().getLabel());
assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
assertEquals("The Uuids do not match", uuid, submitted.getUuid());
// The second post should fail because of constraint failures
ConsumerDTO anotherToSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
anotherToSubmit.setUuid(uuid);
anotherToSubmit.setFact(METADATA_NAME, METADATA_VALUE);
anotherToSubmit.setId(null);
consumerResource.create(anotherToSubmit, principal, null, owner.getKey(), null, true);
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method testUsername.
@Test
public void testUsername() throws IOException, GeneralSecurityException {
// not setting the username here - this should be set by
// examining the user principal
ConsumerDTO consumer = createConsumerDTO("random-consumer", null, null, standardSystemTypeDTO);
consumer = consumerResource.create(consumer, principal, null, null, null, true);
assertEquals(USER_NAME, consumer.getUsername());
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method userwithEmail.
@Test
public void userwithEmail() {
String username = "(foo)@{baz}.[com]&?";
User u = userCurator.create(new User(username, "dontcare"));
ownerAdminRole.addUser(u);
roleCurator.merge(ownerAdminRole);
Principal emailuser = TestUtil.createPrincipal(username, owner, Access.ALL);
setupPrincipal(emailuser);
ConsumerDTO personal = createConsumerDTO(personTypeDTO, ownerDTO);
personal.setName(((UserPrincipal) emailuser).getUsername());
personal = consumerResource.create(personal, emailuser, username, null, null, true);
// Not sure if this should be hard-coded to default
assertEquals(username, personal.getName());
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method compareConsumerRelease.
private void compareConsumerRelease(String release1, String release2, Boolean verify) {
ConsumerDTO consumer = getFakeConsumerDTO();
consumer.setReleaseVersion(release1);
ConsumerDTO incoming = new ConsumerDTO();
incoming.setReleaseVersion(release2);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
this.resource.updateConsumer(consumer.getUuid(), incoming, principal);
verify(consumerCurator, times(1)).update(consumerCaptor.capture());
Consumer mergedConsumer = consumerCaptor.getValue();
if (verify) {
verify(sink).queueEvent((Event) any());
}
assertEquals(incoming.getReleaseVersion(), mergedConsumer.getReleaseVer().getReleaseVer());
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerResourceUpdateTest method ensureGuestEntitlementsAreNotRemovedWhenGuestsAndHostAreTheSame.
@Test
public void ensureGuestEntitlementsAreNotRemovedWhenGuestsAndHostAreTheSame() {
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);
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));
}
Aggregations