Search in sources :

Example 36 with Content

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

the class PoolManagerFunctionalTest method testEntitleByProductsWithModifierAndModifiee.

@Test
public void testEntitleByProductsWithModifierAndModifiee() throws EntitlementRefusedException {
    Product modifier = TestUtil.createProduct("modifier", "modifier");
    Set<String> modified = new HashSet<>();
    modified.add(PRODUCT_VIRT_HOST);
    Content content = TestUtil.createContent("modifier-content", "modifier-content");
    content.setModifiedProductIds(modified);
    modifier.addContent(content, true);
    contentCurator.create(content);
    productCurator.create(modifier);
    this.ownerContentCurator.mapContentToOwner(content, this.o);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    Subscription sub = TestUtil.createSubscription(o, modifier, new HashSet<>());
    sub.setQuantity(5L);
    sub.setStartDate(new Date());
    sub.setEndDate(TestUtil.createDate(3020, 12, 12));
    sub.setModified(new Date());
    sub.setId(Util.generateDbUUID());
    subscriptions.add(sub);
    poolManager.getRefresher(subAdapter, ownerAdapter).add(o).run();
    // This test simulates https://bugzilla.redhat.com/show_bug.cgi?id=676870
    // where entitling first to the modifier then to the modifiee causes the modifier's
    // entitlement cert to get regenerated, but since it's all in the same http call,
    // this ends up causing a hibernate failure (the old cert is asked to be deleted,
    // but it hasn't been saved yet). Since getting the pool ordering right is tricky
    // inside an entitleByProducts call, we do it in two singular calls here.
    AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { "modifier" });
    poolManager.entitleByProducts(data);
    try {
        data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { PRODUCT_VIRT_HOST });
        poolManager.entitleByProducts(data);
    } catch (EntityNotFoundException e) {
        throw e;
    // fail("Hibernate failed to properly save entitlement certs!");
    }
// If we get here, no exception was raised, so we're happy!
}
Also used : Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) EntityNotFoundException(javax.persistence.EntityNotFoundException) LinkedList(java.util.LinkedList) Date(java.util.Date) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) Content(org.candlepin.model.Content) AutobindData(org.candlepin.resource.dto.AutobindData) Subscription(org.candlepin.model.dto.Subscription) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with Content

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

the class ProductDataTest method testPopulateByEntityWithContent.

@Test
public void testPopulateByEntityWithContent() {
    ProductData base = new ProductData();
    Product source = new Product();
    Content[] contentEntities = new Content[] { new Content("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new Content("c2", "content-2", "test_type", "test_label-2", "test_vendor-2"), new Content("c3", "content-3", "test_type", "test_label-3", "test_vendor-3") };
    ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
    ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
    ProductContent pcentity3 = new ProductContent(null, contentEntities[2], true);
    ProductContentData pcdata1 = pcentity1.toDTO();
    ProductContentData pcdata2 = pcentity2.toDTO();
    ProductContentData pcdata3 = pcentity3.toDTO();
    source.setProductContent(Arrays.asList(pcentity1, pcentity2, pcentity3));
    // Verify base state
    assertNull(base.getUuid());
    assertNull(base.getId());
    assertNull(base.getName());
    assertNull(base.getMultiplier());
    assertNull(base.getAttributes());
    assertNull(base.getProductContent());
    assertNull(base.getDependentProductIds());
    assertNull(base.getHref());
    assertNull(base.isLocked());
    base.populate(source);
    // Verify populated state
    assertNull(base.getUuid());
    assertNull(base.getId());
    assertNull(base.getName());
    assertNull(base.getMultiplier());
    assertNull(base.getHref());
    // Note: entities are always locked or unlocked, so this can never be null following a
    // populate.
    assertFalse(base.isLocked());
    // Note: by default, entities have empty collections (NOT null, as was the case before
    // DTOs). As a result, these will never be null after a populate.
    assertNotNull(base.getAttributes());
    assertTrue(base.getAttributes().isEmpty());
    assertNotNull(base.getDependentProductIds());
    assertTrue(base.getDependentProductIds().isEmpty());
    assertNotNull(base.getProductContent());
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata2, pcdata3), base.getProductContent()));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 38 with Content

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

the class ProductDataTest method testAddProductContentByEntity.

@Test
public void testAddProductContentByEntity() {
    ProductData dto = new ProductData();
    Content[] contentEntities = new Content[] { new Content("c1", "content-1", "test_type", "test_label-1", "test_vendor-1"), new Content("c2", "content-2", "test_type", "test_label-2", "test_vendor-2") };
    ProductContent pcentity1 = new ProductContent(null, contentEntities[0], true);
    ProductContent pcentity2 = new ProductContent(null, contentEntities[1], false);
    ProductContent pcentity3 = new ProductContent(null, contentEntities[1], true);
    ContentData[] content = new ContentData[] { contentEntities[0].toDTO(), contentEntities[1].toDTO() };
    ProductContentData pcdata1 = new ProductContentData(content[0], true);
    ProductContentData pcdata2 = new ProductContentData(content[1], false);
    ProductContentData pcdata3 = new ProductContentData(content[1], true);
    assertNull(dto.getProductContent());
    boolean output = dto.addProductContent(pcentity1);
    Collection<ProductContentData> output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
    output = dto.addProductContent(pcentity1);
    output2 = dto.getProductContent();
    assertFalse(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1), output2));
    output = dto.addProductContent(pcentity2);
    output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata2), output2));
    output = dto.addProductContent(pcentity3);
    output2 = dto.getProductContent();
    assertTrue(output);
    assertTrue(Util.collectionsAreEqual(Arrays.asList(pcdata1, pcdata3), output2));
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 39 with Content

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

the class ProductContentDataTest method testPopulateWithEntityContent.

@Test
public void testPopulateWithEntityContent() {
    Content contentEntity = new Content("id1", "name1", "type1", "label1", "vendor1");
    ContentData contentDTO = contentEntity.toDTO();
    ProductContentData base = new ProductContentData();
    ProductContent source = new ProductContent();
    source.setContent(contentEntity);
    base.populate(source);
    assertEquals(contentDTO, base.getContent());
    // This will always be set after a populate
    assertFalse(base.isEnabled());
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 40 with Content

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

the class ProductContentData method populate.

/**
 * Populates this DTO with data from the given source entity.
 *
 * @param source
 *  The source entity from which to copy data
 *
 * @throws IllegalArgumentException
 *  if source is null
 *
 * @return
 *  a reference to this DTO
 */
public ProductContentData populate(ProductContent source) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    Content content = source.getContent();
    this.content = content != null ? (this.content != null ? this.content.populate(content) : content.toDTO()) : null;
    this.enabled = source.isEnabled();
    return this;
}
Also used : ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content)

Aggregations

Content (org.candlepin.model.Content)97 Test (org.junit.Test)45 ProductContent (org.candlepin.model.ProductContent)41 Product (org.candlepin.model.Product)40 Owner (org.candlepin.model.Owner)39 ContentDTO (org.candlepin.dto.api.v1.ContentDTO)25 HashMap (java.util.HashMap)18 EnvironmentContent (org.candlepin.model.EnvironmentContent)17 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)11 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)10 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)9 Transactional (com.google.inject.persist.Transactional)8 Produces (javax.ws.rs.Produces)8 Parameters (junitparams.Parameters)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)7 Path (javax.ws.rs.Path)6 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)6