Search in sources :

Example 81 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class ConsumerCuratorPermissionsTest method testListForOwnerPermissionFiltering.

@Test
public void testListForOwnerPermissionFiltering() {
    User u = setupOnlyMyConsumersPrincipal();
    Consumer c1 = new Consumer("c1", u.getUsername(), owner, consumerType);
    consumerCurator.create(c1);
    Consumer c2 = new Consumer("c2", "anotheruser", owner, consumerType);
    consumerCurator.create(c2);
    List<Consumer> results = consumerCurator.listByOwner(owner).list();
    assertEquals(1, results.size());
    assertEquals(c1.getName(), results.get(0).getName());
}
Also used : User(org.candlepin.model.User) Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 82 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class UsernameConsumersPermissionTest method allowsListOrgConsumers.

@Test
public void allowsListOrgConsumers() {
    Consumer c = new Consumer("consumer", username, owner, null);
    assertTrue(perm.canAccess(owner, SubResource.CONSUMERS, Access.READ_ONLY));
}
Also used : Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 83 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class UsernameConsumersPermissionTest method blocksConsumersInOtherOrgDespiteSameUsername.

@Test
public void blocksConsumersInOtherOrgDespiteSameUsername() {
    Owner other = new Owner("ownerkey2", "My Org 2");
    other.setId(TestUtil.randomString());
    Consumer c = new Consumer("consumer", username, other, null);
    assertFalse(perm.canAccess(c, SubResource.NONE, Access.READ_ONLY));
    assertFalse(perm.canAccess(c, SubResource.NONE, Access.ALL));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 84 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class UsernameConsumersPermissionTest method allowsUsernameConsumersModification.

@Test
public void allowsUsernameConsumersModification() {
    Consumer c = new Consumer("consumer", username, owner, null);
    assertTrue(perm.canAccess(c, SubResource.NONE, Access.ALL));
    assertTrue(perm.canAccess(c, SubResource.NONE, Access.CREATE));
    assertTrue(perm.canAccess(c, SubResource.NONE, Access.READ_ONLY));
}
Also used : Consumer(org.candlepin.model.Consumer) Test(org.junit.Test)

Example 85 with Consumer

use of org.candlepin.model.Consumer in project candlepin by candlepin.

the class EntitlerTest method testCreatedDevSkuWithNoSla.

@Test
public void testCreatedDevSkuWithNoSla() {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    final Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
    devProdDTOs.add(p1.toDTO());
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p1.getId());
    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
    mockUpdateProduct(p1, owner);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    when(productManager.importProducts(eq(owner), any(Map.class), any(Map.class))).thenAnswer(new Answer<ImportResult<Product>>() {

        @Override
        public ImportResult<Product> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            Map<String, ProductData> productData = (Map<String, ProductData>) args[1];
            ImportResult<Product> importResult = new ImportResult<>();
            Map<String, Product> output = importResult.getCreatedEntities();
            // simulate a proper update.
            for (ProductData pdata : productData.values()) {
                if (pdata != null) {
                    if (p1.getId().equals(pdata.getId())) {
                        p1.clearAttributes();
                        if (pdata.getAttributes() != null) {
                            p1.setAttributes(pdata.getAttributes());
                        }
                        output.put(p1.getId(), p1);
                    } else {
                        Product product = new Product(pdata.getId(), pdata.getName());
                        // Do we care about this product? Probably not.
                        output.put(product.getId(), product);
                    }
                }
            }
            return importResult;
        }
    });
    Pool created = entitler.assembleDevPool(devSystem, owner, devSystem.getFact("dev_sku"));
    assertEquals(entitler.DEFAULT_DEV_SLA, created.getProduct().getAttributeValue(Product.Attributes.SUPPORT_LEVEL));
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35