use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.
the class ConsumerResourceIntegrationTest method setUp.
@Before
public void setUp() {
standardSystemType = consumerTypeCurator.create(new ConsumerType("standard-system"));
standardSystemTypeDTO = modelTranslator.translate(standardSystemType, ConsumerTypeDTO.class);
personType = consumerTypeCurator.create(new ConsumerType(ConsumerTypeEnum.PERSON));
personTypeDTO = modelTranslator.translate(personType, ConsumerTypeDTO.class);
owner = ownerCurator.create(new Owner("test-owner"));
ownerDTO = modelTranslator.translate(owner, OwnerDTO.class);
owner.setDefaultServiceLevel(DEFAULT_SERVICE_LEVEL);
ownerCurator.create(owner);
someuser = userCurator.create(new User(USER_NAME, "dontcare"));
ownerAdminRole = createAdminRole(owner);
ownerAdminRole.addUser(someuser);
roleCurator.create(ownerAdminRole);
List<Permission> perms = permFactory.createPermissions(someuser, ownerAdminRole.getPermissions());
principal = new UserPrincipal(USER_NAME, perms, false);
setupPrincipal(principal);
consumer = TestUtil.createConsumer(standardSystemType, owner);
consumerCurator.create(consumer);
product = TestUtil.createProduct();
product.setAttribute(Product.Attributes.SUPPORT_LEVEL, DEFAULT_SERVICE_LEVEL);
productCurator.create(product);
pool = createPool(owner, product, 10L, TestDateUtil.date(2010, 1, 1), TestDateUtil.date(2020, 12, 31));
}
use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.
the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientPermissions.
@Test
public void testValidateShareConsumerRequiresRecipientPermissions() {
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);
Owner o2 = mock(Owner.class);
c.setRecipientOwnerKey("o2");
when(mockOwnerCurator.lookupByKey(eq("o2"))).thenReturn(o2);
when(uap.canAccess(eq(o2), eq(SubResource.ENTITLEMENTS), eq(Access.CREATE))).thenReturn(Boolean.FALSE);
thrown.expect(NotFoundException.class);
thrown.expectMessage("owner with key");
consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerResourceTest method ownerWithInvalidParentWhoseIdAndKeyIsNullCannotBeCreated.
@Test(expected = NotFoundException.class)
public void ownerWithInvalidParentWhoseIdAndKeyIsNullCannotBeCreated() {
OwnerDTO child = new OwnerDTO();
child.setKey("child");
child.setDisplayName("child");
OwnerDTO parent = new OwnerDTO();
parent.setDisplayName("parent");
child.setParentOwner(parent);
this.ownerResource.createOwner(child);
throw new RuntimeException("OwnerResource should have thrown NotFoundException");
}
use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.
the class ProductResourceTest method testGetOwnersForProducts.
@Test
public void testGetOwnersForProducts() {
List<Owner> owners = this.setupDBForOwnerProdTests();
Owner owner1 = owners.get(0);
Owner owner2 = owners.get(1);
Owner owner3 = owners.get(2);
OwnerDTO ownerDTO1 = this.modelTranslator.translate(owner1, OwnerDTO.class);
OwnerDTO ownerDTO2 = this.modelTranslator.translate(owner2, OwnerDTO.class);
OwnerDTO ownerDTO3 = this.modelTranslator.translate(owner3, OwnerDTO.class);
List<OwnerDTO> ownersReturned = null;
ownersReturned = productResource.getProductOwners(Arrays.asList("p1")).list();
assertEquals(Arrays.asList(ownerDTO1, ownerDTO2), ownersReturned);
ownersReturned = productResource.getProductOwners(Arrays.asList("p1", "p2")).list();
assertEquals(Arrays.asList(ownerDTO1, ownerDTO2, ownerDTO3), ownersReturned);
ownersReturned = productResource.getProductOwners(Arrays.asList("p3")).list();
assertEquals(Arrays.asList(ownerDTO3), ownersReturned);
ownersReturned = productResource.getProductOwners(Arrays.asList("nope")).list();
assertEquals(0, ownersReturned.size());
}
use of org.candlepin.dto.rules.v1.OwnerDTO in project candlepin by candlepin.
the class OwnerAccessControlTest method superAdminCanCreateAnOwner.
@Test
public void superAdminCanCreateAnOwner() {
setupAdminPrincipal("dude");
securityInterceptor.enable();
OwnerDTO dto = new OwnerDTO();
dto.setKey("Test Owner");
dto.setDisplayName("Test Owner");
dto = resource.createOwner(dto);
assertNotNull(dto.getId());
assertNotNull(ownerCurator.find(dto.getId()));
}
Aggregations