Search in sources :

Example 56 with Content

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

the class ContentResourceTest method getContent.

@Test
public void getContent() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    ContentDTO expected = this.modelTranslator.translate(content, ContentDTO.class);
    when(cqmock.list()).thenReturn(Arrays.asList(owner));
    when(oc.listAll()).thenReturn(cqmock);
    when(cc.lookupByUuid(eq("10"))).thenReturn(content);
    ContentDTO output = cr.getContent("10");
    assertEquals(expected, output);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) Test(org.junit.Test)

Example 57 with Content

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

the class OwnerContentResourceTest method createContent.

@Test
public void createContent() {
    Owner owner = this.createOwner("test_owner");
    ContentDTO cdto = TestUtil.createContentDTO("test_content");
    cdto.setLabel("test-label");
    cdto.setType("test-test");
    cdto.setVendor("test-vendor");
    assertNull(this.ownerContentCurator.getContentById(owner, cdto.getId()));
    ContentDTO output = this.ownerContentResource.createContent(owner.getKey(), cdto);
    assertNotNull(output);
    assertEquals(cdto.getId(), output.getId());
    Content entity = this.ownerContentCurator.getContentById(owner, cdto.getId());
    assertNotNull(entity);
    assertEquals(cdto.getName(), entity.getName());
    assertEquals(cdto.getLabel(), entity.getLabel());
    assertEquals(cdto.getType(), entity.getType());
    assertEquals(cdto.getVendor(), entity.getVendor());
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 58 with Content

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

the class OwnerContentResourceTest method listContent.

@Test
public void listContent() throws Exception {
    Owner owner = this.createOwner("test_owner");
    Content content = this.createContent("test_content", "test_content", owner);
    ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
    CandlepinQuery<ContentDTO> response = this.ownerContentResource.listContent(owner.getKey());
    assertNotNull(response);
    Collection<ContentDTO> received = response.list();
    assertEquals(1, received.size());
    assertTrue(received.contains(cdto));
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) Test(org.junit.Test)

Example 59 with Content

use of org.candlepin.model.Content 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 60 with Content

use of org.candlepin.model.Content 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)

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