Search in sources :

Example 16 with ConsumerDTO

use of org.candlepin.dto.manifest.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);
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) Test(org.junit.Test)

Example 17 with ConsumerDTO

use of org.candlepin.dto.manifest.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());
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) Test(org.junit.Test)

Example 18 with ConsumerDTO

use of org.candlepin.dto.manifest.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());
}
Also used : User(org.candlepin.model.User) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 19 with ConsumerDTO

use of org.candlepin.dto.manifest.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());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO)

Example 20 with ConsumerDTO

use of org.candlepin.dto.manifest.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));
}
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)

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