Search in sources :

Example 61 with ConsumerDTO

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

the class ConsumerResourceIntegrationTest method testCreateConsumerVsDefaultServiceLevelForOwner.

@Test
@SuppressWarnings("checkstyle:indentation")
public void testCreateConsumerVsDefaultServiceLevelForOwner() {
    ConsumerDTO toSubmit = createConsumerDTO(CONSUMER_NAME, USER_NAME, null, standardSystemTypeDTO);
    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);
    assertEquals(DEFAULT_SERVICE_LEVEL, submitted.getServiceLevel());
}
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 62 with ConsumerDTO

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

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

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

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

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