Search in sources :

Example 96 with Owner

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

the class ContentManagerTest method testCreateContent.

@Test
public void testCreateContent() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    ContentDTO dto = TestUtil.createContentDTO("c1", "content-1");
    dto.setLabel("test-label");
    dto.setType("test-test");
    dto.setVendor("test-vendor");
    assertNull(this.ownerContentCurator.getContentById(owner, dto.getId()));
    Content output = this.contentManager.createContent(dto, owner);
    assertEquals(output, this.ownerContentCurator.getContentById(owner, dto.getId()));
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 97 with Owner

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

the class ContentManagerTest method testUpdateContentNoChange.

@Test
public void testUpdateContentNoChange() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "product-1", owner);
    Content content = this.createContent("c1", "content-1", owner);
    product.addContent(content, true);
    product = this.productCurator.merge(product);
    ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
    Content output = this.contentManager.updateContent(cdto, owner, true);
    assertEquals(output.getUuid(), content.getUuid());
    assertEquals(output, content);
    verifyZeroInteractions(this.mockEntCertGenerator);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) Test(org.junit.Test)

Example 98 with Owner

use of org.candlepin.model.Owner 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)

Example 99 with Owner

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

the class EntitlerTest method testDevPoolCreationAtBindFailStandalone.

@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailStandalone() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    devProdDTOs.add(p.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(true);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 100 with Owner

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

the class EntitlerTest method testDevPoolCreationAtBind.

@Test
public void testDevPoolCreationAtBind() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    p.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
    devProdDTOs.add(p.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Pool devPool = mock(Pool.class);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
    this.mockProducts(owner, p);
    this.mockProductImport(owner, p);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    when(pm.createPool(any(Pool.class))).thenReturn(devPool);
    when(devPool.getId()).thenReturn("test_pool_id");
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
    verify(pm).createPool(any(Pool.class));
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29