Search in sources :

Example 16 with OwnerDTO

use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.

the class OwnerAccessControlTest method consumerCannotCreateAnOwner.

@Test(expected = ForbiddenException.class)
public void consumerCannotCreateAnOwner() {
    Consumer consumer = createConsumer(owner);
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    securityInterceptor.enable();
    OwnerDTO dto = new OwnerDTO();
    dto.setKey("Test Owner");
    dto.setDisplayName("Test Owner");
    resource.createOwner(dto);
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 17 with OwnerDTO

use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.

the class OwnerAccessControlTest method ownerAdminCannotCreateAnOwner.

@Test(expected = ForbiddenException.class)
public void ownerAdminCannotCreateAnOwner() {
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    OwnerDTO dto = new OwnerDTO();
    dto.setKey("Test Owner");
    dto.setDisplayName("Test Owner");
    resource.createOwner(dto);
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Example 18 with OwnerDTO

use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientFact.

@Test
public void testValidateShareConsumerRequiresRecipientFact() {
    ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
    ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
    OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
    ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
    UserPrincipal uap = mock(UserPrincipal.class);
    when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
    Owner o = mock(Owner.class);
    when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
    c.setFact("foo", "bar");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("must specify a recipient org");
    consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 19 with OwnerDTO

use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.

the class OwnerResourceTest method testUpdateOwner.

@Test
public void testUpdateOwner() {
    config.setProperty(ConfigProperties.STANDALONE, "false");
    Owner owner = new Owner("Test Owner", "test");
    ownerCurator.create(owner);
    Product prod1 = this.createProduct(owner);
    prod1.setAttribute(Product.Attributes.SUPPORT_LEVEL, "premium");
    productCurator.merge(prod1);
    Product prod2 = this.createProduct(owner);
    prod2.setAttribute(Product.Attributes.SUPPORT_LEVEL, "standard");
    productCurator.merge(prod2);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub1 = TestUtil.createSubscription(owner, prod1, new HashSet<>());
    sub1.setId(Util.generateDbUUID());
    sub1.setQuantity(2000L);
    sub1.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub1.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub1.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub1);
    Subscription sub2 = TestUtil.createSubscription(owner, prod2, new HashSet<>());
    sub2.setId(Util.generateDbUUID());
    sub2.setQuantity(2000L);
    sub2.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub2.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub2.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub2);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    owner.setDefaultServiceLevel("premium");
    Owner parentOwner1 = ownerCurator.create(new Owner("Paren Owner 1", "parentTest1"));
    Owner parentOwner2 = ownerCurator.create(new Owner("Paren Owner 2", "parentTest2"));
    owner.setParentOwner(parentOwner1);
    ownerCurator.merge(owner);
    ownerCurator.flush();
    // Update with Display Name Only
    OwnerDTO dto = new OwnerDTO();
    dto.setDisplayName("New Name");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner1, owner.getParentOwner());
    assertEquals("premium", owner.getDefaultServiceLevel());
    assertFalse(owner.isAutobindDisabled());
    // Update with Default Service Level only
    dto = new OwnerDTO();
    dto.setDefaultServiceLevel("standard");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals("standard", owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner1, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Update with Parent Owner only
    OwnerDTO parentDto = new OwnerDTO();
    parentDto.setId(parentOwner2.getId());
    dto = new OwnerDTO();
    dto.setParentOwner(parentDto);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertEquals(parentOwner2, owner.getParentOwner());
    assertEquals("standard", owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertFalse(owner.isAutobindDisabled());
    // Update with empty Service Level only
    dto = new OwnerDTO();
    dto.setDefaultServiceLevel("");
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Update autobind with disabled value.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(true);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertTrue(owner.isAutobindDisabled());
    // Update autobind with enabled value.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(false);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
    // Unset autobindDisabled results in no update.
    dto = new OwnerDTO();
    dto.setAutobindDisabled(null);
    ownerResource.updateOwner(owner.getKey(), dto);
    assertNull(owner.getDefaultServiceLevel());
    assertEquals("New Name", owner.getDisplayName());
    assertEquals(parentOwner2, owner.getParentOwner());
    assertFalse(owner.isAutobindDisabled());
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 20 with OwnerDTO

use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.

the class ConsumerImporterTest method importConsumerWithNullUuidOnOwnerShouldSetUuid.

@Test
public void importConsumerWithNullUuidOnOwnerShouldSetUuid() throws ImporterException {
    OwnerDTO ownerDTO = mock(OwnerDTO.class);
    Owner owner = mock(Owner.class);
    ConsumerDTO consumer = mock(ConsumerDTO.class);
    ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
    when(ownerDTO.getId()).thenReturn("test-owner-id");
    when(consumer.getUuid()).thenReturn("test-uuid");
    when(consumer.getOwner()).thenReturn(ownerDTO);
    when(consumer.getType()).thenReturn(type);
    IdentityCertificate idCert = new IdentityCertificate();
    idCert.setSerial(new CertificateSerial());
    importer.store(owner, consumer, new ConflictOverrides(), idCert);
    // now verify that the owner has the upstream consumer set
    ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
    verify(owner).setUpstreamConsumer(arg.capture());
    assertEquals("test-uuid", arg.getValue().getUuid());
    verify(curator).merge(owner);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) CertificateSerial(org.candlepin.model.CertificateSerial) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)16 Owner (org.candlepin.model.Owner)16 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)9 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)6 ConsumerType (org.candlepin.model.ConsumerType)5 UserPrincipal (org.candlepin.auth.UserPrincipal)4 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)3 CertificateSerial (org.candlepin.model.CertificateSerial)3 IdentityCertificate (org.candlepin.model.IdentityCertificate)3 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)3 File (java.io.File)2 Date (java.util.Date)2 Access (org.candlepin.auth.Access)2 SubResource (org.candlepin.auth.SubResource)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)2 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)2 OwnerCurator (org.candlepin.model.OwnerCurator)2