Search in sources :

Example 66 with ConsumerDTO

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

the class ConsumerResourceIntegrationTest method onlyOnePersonalConsumer.

@Test(expected = BadRequestException.class)
public void onlyOnePersonalConsumer() {
    ConsumerDTO personal = createConsumerDTO(personTypeDTO, ownerDTO);
    consumerResource.create(personal, principal, null, null, null, true);
    personal = createConsumerDTO(personTypeDTO, ownerDTO);
    consumerResource.create(personal, principal, null, null, null, true);
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) Test(org.junit.Test)

Example 67 with ConsumerDTO

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

the class ConsumerResourceIntegrationTest method testCreateConsumer.

@Test
@SuppressWarnings("checkstyle:indentation")
public void testCreateConsumer() {
    ConsumerDTO toSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
    toSubmit.setFact(METADATA_NAME, METADATA_VALUE);
    ConsumerDTO submitted = consumerResource.create(toSubmit, new UserPrincipal(someuser.getUsername(), Arrays.asList(new Permission[] { new OwnerPermission(owner, Access.ALL) }), false), someuser.getUsername(), owner.getKey(), null, true);
    assertNotNull(submitted);
    assertNotNull(consumerCurator.find(submitted.getId()));
    assertEquals(standardSystemType.getLabel(), submitted.getType().getLabel());
    assertEquals(METADATA_VALUE, submitted.getFact(METADATA_NAME));
}
Also used : OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) TestUtil.createConsumerDTO(org.candlepin.test.TestUtil.createConsumerDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 68 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method ensureGuestEntitlementsAreNotRevokedWhenGuestIsRemovedFromHost.

@Test
public void ensureGuestEntitlementsAreNotRevokedWhenGuestIsRemovedFromHost() {
    String uuid = "TEST_CONSUMER";
    Consumer host = createConsumerWithGuests(createOwner(), "Guest 1", "Guest 2");
    host.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
    ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 2");
    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(consumerCurator).findByVirtUuid(eq("Guest 1"));
    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)

Example 69 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method setStatusOnUpdate.

@Test
public void setStatusOnUpdate() throws Exception {
    Product productA = TestUtil.createProduct("Product A");
    Product productB = TestUtil.createProduct("Product B");
    Product productC = TestUtil.createProduct("Product C");
    Consumer consumer = getFakeConsumer();
    consumer.addInstalledProduct(new ConsumerInstalledProduct(consumer, productA));
    consumer.addInstalledProduct(new ConsumerInstalledProduct(consumer, productB));
    ConsumerDTO incoming = new ConsumerDTO();
    incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productB.getId(), productB.getName()));
    incoming.addInstalledProduct(new ConsumerInstalledProductDTO(productC.getId(), productC.getName()));
    this.resource.updateConsumer(consumer.getUuid(), incoming, principal);
    verify(sink).queueEvent((Event) any());
    verify(complianceRules).getStatus(eq(consumer), any(Date.class), any(Boolean.class), any(Boolean.class));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProductDTO(org.candlepin.dto.api.v1.ConsumerInstalledProductDTO) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Date(java.util.Date) Test(org.junit.Test)

Example 70 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method canUpdateConsumerEnvironment.

@Test
public void canUpdateConsumerEnvironment() {
    Environment changedEnvironment = new Environment("42", "environment", null);
    Consumer existing = getFakeConsumer();
    ConsumerDTO updated = new ConsumerDTO();
    updated.setEnvironment(translator.translate(changedEnvironment, EnvironmentDTO.class));
    when(environmentCurator.find(changedEnvironment.getId())).thenReturn(changedEnvironment);
    resource.updateConsumer(existing.getUuid(), updated, principal);
    verify(poolManager, atMost(1)).regenerateCertificatesOf(existing, true);
    verify(sink).queueEvent((Event) any());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) EnvironmentDTO(org.candlepin.dto.api.v1.EnvironmentDTO) Environment(org.candlepin.model.Environment) 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