Search in sources :

Example 11 with OwnerDTO

use of org.candlepin.dto.manifest.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));
}
Also used : Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) OwnerPermission(org.candlepin.auth.permissions.OwnerPermission) Permission(org.candlepin.auth.permissions.Permission) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Before(org.junit.Before)

Example 12 with OwnerDTO

use of org.candlepin.dto.manifest.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);
}
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 13 with OwnerDTO

use of org.candlepin.dto.manifest.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");
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Example 14 with OwnerDTO

use of org.candlepin.dto.manifest.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());
}
Also used : Owner(org.candlepin.model.Owner) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Test(org.junit.Test)

Example 15 with OwnerDTO

use of org.candlepin.dto.manifest.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()));
}
Also used : OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) 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