Search in sources :

Example 26 with ContentDTO

use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.

the class OwnerContentResourceTest method updateLockedContent.

@Test(expected = ForbiddenException.class)
public void updateLockedContent() {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = TestUtil.createContentDTO("test_content", "updated_name");
    content.setLocked(true);
    this.contentCurator.merge(content);
    assertNotNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    try {
        this.ownerContentResource.updateContent(owner.getKey(), cdto.getId(), 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 27 with ContentDTO

use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.

the class OwnerContentResourceTest method getContent.

@Test
public void getContent() {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO output = this.ownerContentResource.getContent(owner.getKey(), content.getId());
    assertNotNull(output);
    assertEquals(content.getId(), output.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 28 with ContentDTO

use of org.candlepin.dto.manifest.v1.ContentDTO 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 29 with ContentDTO

use of org.candlepin.dto.manifest.v1.ContentDTO 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 30 with ContentDTO

use of org.candlepin.dto.manifest.v1.ContentDTO in project candlepin by candlepin.

the class OwnerContentResourceTest method getContentNotFound.

@Test(expected = NotFoundException.class)
public void getContentNotFound() {
    Owner owner = this.createOwner("test_owner");
    ContentDTO output = this.ownerContentResource.getContent(owner.getKey(), "test_content");
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Aggregations

ContentDTO (org.candlepin.dto.api.v1.ContentDTO)35 Test (org.junit.Test)28 Owner (org.candlepin.model.Owner)26 Content (org.candlepin.model.Content)25 Product (org.candlepin.model.Product)13 ProductDTO (org.candlepin.dto.api.v1.ProductDTO)7 ContentDTO (org.candlepin.dto.manifest.v1.ContentDTO)7 ProductContent (org.candlepin.model.ProductContent)7 LinkedList (java.util.LinkedList)5 ProductContentDTO (org.candlepin.dto.api.v1.ProductDTO.ProductContentDTO)5 ProductDTO (org.candlepin.dto.manifest.v1.ProductDTO)5 Transactional (com.google.inject.persist.Transactional)4 Parameters (junitparams.Parameters)4 ContentData (org.candlepin.model.dto.ContentData)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)3 ProductContentData (org.candlepin.model.dto.ProductContentData)3