@Test(expected = NotFoundException.class)
  public void testUpdateContentThrowsExceptionWhenOwnerDoesNotExist() {
    Content content = mock(Content.class);
    when(cc.find(any(String.class))).thenReturn(null);

    ocr.updateContent("owner", "someId", content);
  }
  @Test
  public void testUpdateContent() {
    final String ownerId = "owner";
    final String productId = "productId";
    final String contentId = "10";

    Owner owner = mock(Owner.class);
    Product product = mock(Product.class);
    Content content = mock(Content.class);

    when(product.getId()).thenReturn(productId);
    when(product.getOwner()).thenReturn(owner);
    when(content.getId()).thenReturn(contentId);
    when(content.getOwner()).thenReturn(owner);

    when(oc.lookupByKey(eq(ownerId))).thenReturn(owner);
    when(cc.lookupById(eq(owner), eq(contentId))).thenReturn(content);
    when(cc.createOrUpdate(eq(content))).thenReturn(content);
    when(productCurator.getProductsWithContent(eq(owner), eq(Arrays.asList(contentId))))
        .thenReturn(Arrays.asList(product));

    ocr.updateContent(ownerId, contentId, content);

    verify(cc).lookupById(eq(owner), eq(contentId));
    verify(cc).createOrUpdate(eq(content));
    verify(productCurator).getProductsWithContent(eq(owner), eq(Arrays.asList(contentId)));
    verify(poolManager).regenerateCertificatesOf(eq(owner), eq(productId), eq(true));
  }
  @Test(expected = NotFoundException.class)
  public void getContentNull() {
    Owner owner = mock(Owner.class);
    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);

    when(cc.lookupById(any(Owner.class), anyString())).thenReturn(null);
    ocr.getContent("owner", "10");
  }
  @Test
  public void listContent() {
    Owner owner = mock(Owner.class);
    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);

    ocr.list("owner");
    verify(cc, atLeastOnce()).listByOwner(eq(owner));
  }
  @Test
  public void getContent() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);

    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);
    when(cc.lookupById(eq(owner), eq("10"))).thenReturn(content);

    assertEquals(content, ocr.getContent("owner", "10"));
  }
  @Test(expected = NotFoundException.class)
  public void testUpdateContentThrowsExceptionWhenContentDoesNotExist() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);

    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);
    when(cc.lookupById(eq(owner), any(String.class))).thenReturn(null);

    ocr.updateContent("owner", "someId", content);
  }
  @Test(expected = NotFoundException.class)
  public void deleteContentNull() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);

    when(content.getId()).thenReturn("10");
    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);
    when(cc.lookupById(eq(owner), eq("10"))).thenReturn(null);

    ocr.remove("owner", "10");
    verify(cc, never()).delete(eq(content));
  }
  @Test
  public void createContentNull() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);

    when(content.getId()).thenReturn("10");
    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);
    when(cc.lookupById(eq(owner), eq("10"))).thenReturn(null);

    ocr.createContent("owner", content);
    verify(cc, atLeastOnce()).create(content);
  }
  @Test
  public void deleteContent() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);

    when(content.getId()).thenReturn("10");
    when(content.getOwner()).thenReturn(owner);
    when(oc.lookupByKey(eq("owner"))).thenReturn(owner);
    when(cc.lookupById(eq(owner), eq("10"))).thenReturn(content);

    EnvironmentContent ec = new EnvironmentContent(mock(Environment.class), content, true);
    List<EnvironmentContent> envContents = Arrays.asList(ec);
    when(envContentCurator.lookupByContent(owner, content.getId())).thenReturn(envContents);

    ocr.remove("owner", "10");

    verify(cc, atLeastOnce()).delete(eq(content));
    verify(envContentCurator, atLeastOnce()).delete(eq(ec));
  }