Search in sources :

Example 61 with Content

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

the class OwnerContentResourceTest method createContentWhenContentAlreadyExistsAndLocked.

@Test(expected = ForbiddenException.class)
public void createContentWhenContentAlreadyExistsAndLocked() {
    // Note:
    // The current behavior of createContent is to update content if content already exists
    // with the given RHID. So, our expected behavior in this test is to trigger an update.
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    cdto.setLabel("test-label");
    cdto.setType("test-test");
    cdto.setVendor("test-vendor");
    content.setLocked(true);
    this.contentCurator.merge(content);
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    try {
        ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), cdto);
    } catch (ForbiddenException e) {
        Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
        assertNotNull(entity);
        assertEquals(content, entity);
        assertNotEquals(cdto.getName(), entity.getName());
        throw e;
    }
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 62 with Content

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

the class OwnerContentResourceTest method createContentWhenContentAlreadyExists.

@Test
public void createContentWhenContentAlreadyExists() {
    // Note:
    // The current behavior of createContent is to update content if content already exists
    // with the given RHID. So, our expected behavior in this test is to trigger an update.
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    cdto.setLabel("test-label");
    cdto.setType("test-test");
    cdto.setVendor("test-vendor");
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), cdto);
    assertNotNull(output);
    assertEquals(cdto.getId(), output.getId());
    assertEquals(cdto.getName(), output.getName());
    Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
    assertNotNull(entity);
    assertEquals(cdto.getName(), entity.getName());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 63 with Content

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

the class OwnerContentResourceTest method updateContent.

@Test
public void updateContent() {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    ContentDTO output = this.ownerContentResource.updateContent(owner.getKey(), cdto.getId(), cdto);
    assertNotNull(output);
    assertEquals(cdto.getId(), output.getId());
    assertEquals(cdto.getName(), output.getName());
    Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
    assertNotNull(entity);
    assertEquals(cdto.getName(), entity.getName());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 64 with Content

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

the class DefaultEntitlementCertServiceAdapterTest method testSpecificLargeContent.

@Test
public void testSpecificLargeContent() throws IOException {
    Set<Product> products = new HashSet<>();
    products.add(largeContentProduct);
    largeContentProduct.setProductContent(null);
    for (Content content : largeContent) {
        largeContentProduct.addContent(content, false);
    }
    consumer.setFact("system.certificate_version", "3.3");
    Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(product, getProductModels(product, products, "prefix", largeContentEntitlement), "prefix", null);
    Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
    for (X509ByteExtensionWrapper ext : byteExtensions) {
        byteMap.put(ext.getOid(), ext);
    }
    assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
    List<String> contentSetList = new ArrayList<>();
    try {
        contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEquals(largeContent.size(), contentSetList.size());
    for (String url : largeTestUrls) {
        assertTrue(contentSetList.contains("/prefix" + url));
    }
    List<String> testList = Arrays.asList(largeTestUrls);
    for (String url : contentSetList) {
        assertTrue(testList.contains(url.substring(7)));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with Content

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

the class DatabaseTestFixture method createContent.

protected Content createContent(String id, String name, Owner... owners) {
    Content content = TestUtil.createContent(id, name);
    content = this.contentCurator.create(content);
    this.ownerContentCurator.mapContentToOwners(content, owners);
    return content;
}
Also used : Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent)

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