Search in sources :

Example 71 with Product

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

the class ProductManagerTest method testCreateProductThatAlreadyExists.

@Test(expected = IllegalStateException.class)
public void testCreateProductThatAlreadyExists() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    ProductDTO dto = TestUtil.createProductDTO("p1", "prod1");
    Product output = this.productManager.createProduct(dto, owner);
    assertNotNull(output);
    assertEquals(output, this.ownerProductCurator.getProductById(owner, dto.getId()));
    this.productManager.createProduct(dto, owner);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Test(org.junit.Test)

Example 72 with Product

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

the class ProductManagerTest method testUpdateProduct.

@Test
@Parameters({ "false", "true" })
public void testUpdateProduct(boolean regenCerts) {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "prod1", owner);
    ProductDTO update = TestUtil.createProductDTO("p1", "new product name");
    Product output = this.productManager.updateProduct(update, owner, regenCerts);
    assertNotEquals(output.getUuid(), product.getUuid());
    assertEquals(output.getName(), update.getName());
    // We expect the original to be kept around as an orphan until the orphan removal job
    // gets around to removing them
    assertNotNull(this.productCurator.find(product.getUuid()));
    assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
    assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
    if (regenCerts) {
        // TODO: Is there a better way to do this? We won't know the exact product instance,
        // we just know that a product should be refreshed as a result of this operation.
        verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner)), anyCollectionOf(Product.class), anyBoolean());
    } else {
        verifyZeroInteractions(this.mockEntCertGenerator);
    }
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 73 with Product

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

the class ProductManagerTest method testUpdateProductDivergeFromExisting.

@Test
@Parameters({ "false", "true" })
public void testUpdateProductDivergeFromExisting(boolean regenCerts) {
    Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
    Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
    Product product = this.createProduct("p1", "prod1", owner1, owner2);
    ProductDTO update = TestUtil.createProductDTO("p1", "updated product");
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    Product output = this.productManager.updateProduct(update, owner1, regenCerts);
    assertNotEquals(output.getUuid(), product.getUuid());
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
    assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
    assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
    if (regenCerts) {
        verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner1)), anyCollectionOf(Product.class), anyBoolean());
    } else {
        verifyZeroInteractions(this.mockEntCertGenerator);
    }
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 74 with Product

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

the class ProductManagerTest method testUpdateProductNoChange.

@Test
public void testUpdateProductNoChange() {
    Owner owner = this.createOwner("test-owner", "Test Owner");
    Product product = this.createProduct("p1", "prod1", owner);
    Product output = this.productManager.updateProduct(product.toDTO(), owner, true);
    assertEquals(output.getUuid(), product.getUuid());
    assertEquals(output, product);
    verifyZeroInteractions(this.mockEntCertGenerator);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Test(org.junit.Test)

Example 75 with Product

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

the class ActivationKeyTranslatorTest method verifyOutput.

@Override
protected void verifyOutput(ActivationKey source, ActivationKeyDTO dest, boolean childrenGenerated) {
    if (source != null) {
        assertEquals(source.getId(), dest.getId());
        assertEquals(source.getName(), dest.getName());
        assertEquals(source.getDescription(), dest.getDescription());
        assertEquals(source.getServiceLevel(), dest.getServiceLevel());
        assertEquals(source.isAutoAttach(), dest.isAutoAttach());
        if (childrenGenerated) {
            this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
            for (Product prod : source.getProducts()) {
                for (String prodDto : dest.getProductIds()) {
                    assertNotNull(prodDto);
                    if (prodDto.equals(prod.getId())) {
                    // Nothing else to assert on, since prodDto only holds the product id.
                    }
                }
            }
            for (ActivationKeyPool akPool : source.getPools()) {
                for (ActivationKeyDTO.ActivationKeyPoolDTO akPoolDto : dest.getPools()) {
                    assertNotNull(akPoolDto);
                    if (akPoolDto.getPoolId().equals(akPool.getId())) {
                        assertEquals(akPool.getQuantity(), akPoolDto.getQuantity());
                    }
                }
            }
            for (ActivationKeyContentOverride akOverride : source.getContentOverrides()) {
                for (ActivationKeyDTO.ActivationKeyContentOverrideDTO akOverrideDto : dest.getContentOverrides()) {
                    assertNotNull(akOverrideDto);
                    if (akOverrideDto.getName().equals(akOverride.getName())) {
                        assertEquals(akOverrideDto.getContentLabel(), akOverride.getContentLabel());
                        assertEquals(akOverrideDto.getValue(), akOverride.getValue());
                    }
                }
            }
            Release releaseSource = source.getReleaseVer();
            String releaseDestination = dest.getReleaseVersion();
            if (releaseSource != null) {
                assertEquals(releaseSource.getReleaseVer(), releaseDestination);
            } else {
                assertNull(releaseDestination);
            }
        } else {
            assertNull(dest.getOwner());
            assertNull(dest.getProductIds());
            assertNull(dest.getPools());
            assertNull(dest.getContentOverrides());
            assertNull(dest.getReleaseVersion());
        }
    } else {
        assertNull(dest);
    }
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Release(org.candlepin.model.Release) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Aggregations

Product (org.candlepin.model.Product)407 Test (org.junit.Test)281 Pool (org.candlepin.model.Pool)216 Owner (org.candlepin.model.Owner)153 Consumer (org.candlepin.model.Consumer)112 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)108 HashSet (java.util.HashSet)84 Date (java.util.Date)74 ArrayList (java.util.ArrayList)69 Entitlement (org.candlepin.model.Entitlement)67 LinkedList (java.util.LinkedList)66 HashMap (java.util.HashMap)65 Subscription (org.candlepin.model.dto.Subscription)47 Content (org.candlepin.model.Content)40 ValidationResult (org.candlepin.policy.ValidationResult)38 SourceSubscription (org.candlepin.model.SourceSubscription)36 Matchers.anyString (org.mockito.Matchers.anyString)31 List (java.util.List)29 PoolQuantity (org.candlepin.model.PoolQuantity)29 DateRange (org.candlepin.policy.js.compliance.DateRange)27