Search in sources :

Example 11 with ProductDTO

use of org.candlepin.dto.api.v1.ProductDTO 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 12 with ProductDTO

use of org.candlepin.dto.api.v1.ProductDTO 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 13 with ProductDTO

use of org.candlepin.dto.api.v1.ProductDTO 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 14 with ProductDTO

use of org.candlepin.dto.api.v1.ProductDTO in project candlepin by candlepin.

the class ProductDTOTranslatorTest method initSourceObject.

@Override
protected ProductDTO initSourceObject() {
    ProductDTO source = new ProductDTO();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("attrib_1", "attrib_value_1");
    attributes.put("attrib_2", "attrib_value_2");
    attributes.put("attrib_3", "attrib_value_3");
    Collection<String> depProdIds = new LinkedList<>();
    depProdIds.add("dep_prod_1");
    depProdIds.add("dep_prod_2");
    depProdIds.add("dep_prod_3");
    source.setUuid("test_uuid");
    source.setId("test_id");
    source.setName("test_name");
    source.setMultiplier(10L);
    source.setAttributes(attributes);
    source.setDependentProductIds(depProdIds);
    for (int i = 0; i < 3; ++i) {
        ContentDTO contentDTO = new ContentDTO();
        contentDTO.setId("content-dto-" + i);
        contentDTO.setUuid(contentDTO.getId() + "_uuid");
        ProductContentDTO pcDTO = new ProductContentDTO(contentDTO, true);
        source.addProductContent(pcDTO);
    }
    return source;
}
Also used : ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) HashMap(java.util.HashMap) ProductContentDTO(org.candlepin.dto.manifest.v1.ProductDTO.ProductContentDTO) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) LinkedList(java.util.LinkedList)

Example 15 with ProductDTO

use of org.candlepin.dto.api.v1.ProductDTO in project candlepin by candlepin.

the class EntitlementImporter method associateProvidedProducts.

/*
     * Transfer associations to provided and derived provided products over to the
     * subscription.
     *
     * WARNING: This is a bit tricky due to backward compatibility issues. Prior to
     * candlepin 2.0, pools serialized a collection of disjoint provided product info,
     * an object with just a product ID and name, not directly linked to anything in the db.
     *
     * In candlepin 2.0 we have referential integrity and links to full product objects,
     * but we need to maintain both API and import compatibility with old manifests and
     * servers that may import new manifests.
     *
     * To do this, we serialize the providedProductDtos and derivedProvidedProductDtos
     * collections on pool which keeps the API/manifest JSON identical to what it was
     * before. On import we load into these transient collections, and here we transfer
     * to the actual persisted location.
     */
public void associateProvidedProducts(Map<String, ProductDTO> productsById, Entitlement entitlement, Subscription subscription) throws SyncDataFormatException {
    // Associate main provided products:
    Set<ProductData> providedProducts = new HashSet<>();
    entitlement.getPool().populateAllTransientProvidedProducts(productCurator);
    for (ProvidedProduct providedProduct : entitlement.getPool().getProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, providedProduct.getProductId());
        providedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setProvidedProducts(providedProducts);
    // Associate derived provided products:
    Set<ProductData> derivedProvidedProducts = new HashSet<>();
    for (ProvidedProduct pp : entitlement.getPool().getDerivedProvidedProductDtos()) {
        ProductDTO productDTO = this.findProduct(productsById, pp.getProductId());
        derivedProvidedProducts.add(this.translator.translate(productDTO, ProductData.class));
    }
    subscription.setDerivedProvidedProducts(derivedProvidedProducts);
    log.debug("Subscription has {} provided products.", derivedProvidedProducts.size());
    log.debug("Subscription has {} derived provided products.", derivedProvidedProducts.size());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) ProvidedProduct(org.candlepin.model.ProvidedProduct) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) HashSet(java.util.HashSet)

Aggregations

ProductDTO (org.candlepin.dto.api.v1.ProductDTO)29 Product (org.candlepin.model.Product)28 Test (org.junit.Test)27 Owner (org.candlepin.model.Owner)25 Content (org.candlepin.model.Content)15 ProductContent (org.candlepin.model.ProductContent)13 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)12 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)11 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)7 Parameters (junitparams.Parameters)6 Transactional (com.google.inject.persist.Transactional)5 Reader (java.io.Reader)5 LinkedList (java.util.LinkedList)5 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)5 StringReader (java.io.StringReader)4 HashSet (java.util.HashSet)4 Subscription (org.candlepin.model.dto.Subscription)4 HashMap (java.util.HashMap)3 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3