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