OwnerContentCurator extends AbstractHibernateCurator<OwnerContent> { @Transactional public boolean mapContentToOwner(Content content, Owner owner) { if (!this.isContentMappedToOwner(content, owner)) { this.create(new OwnerContent(owner, content)); return true; } return false; } OwnerContentCurator(); Content getContentById(Owner owner, String contentId); @Transactional Content getContentById(String ownerId, String contentId); CandlepinQuery<Owner> getOwnersByContent(Content content); CandlepinQuery<Owner> getOwnersByContent(String contentId); Collection<String> getContentUuidsByOwner(Owner owner); Collection<String> getContentUuidsByOwner(String ownerId); CandlepinQuery<Content> getContentByOwner(Owner owner); CandlepinQuery<Content> getContentByOwner(String ownerId); CandlepinQuery<Content> getContentByIds(Owner owner, Collection<String> contentIds); CandlepinQuery<Content> getContentByIds(String ownerId, Collection<String> contentIds); @Transactional long getOwnerCount(Content content); @Transactional boolean contentExists(Owner owner, String contentId); @Transactional boolean isContentMappedToOwner(Content content, Owner owner); @Transactional boolean mapContentToOwner(Content content, Owner owner); @Transactional int mapContentToOwners(Content content, Owner... owners); @Transactional int mapOwnerToContent(Owner owner, Content... content); @Transactional boolean removeOwnerFromContent(Content content, Owner owner); @Transactional int clearOwnersForContent(Content content); @Transactional int clearContentForOwner(Owner owner); @SuppressWarnings("checkstyle:indentation") CandlepinQuery<Content> getContentByVersions(Owner owner, Map<String, Integer> contentVersions); CandlepinQuery<Content> getOrphanedContent(); @Transactional void updateOwnerContentReferences(Owner owner, Map<String, String> contentUuidMap); @Transactional void removeOwnerContentReferences(Owner owner, Collection<String> contentUuids);  }
@Test public void testMapContentToOwner() { Owner owner1 = this.createOwner(); Owner owner2 = this.createOwner(); Owner owner3 = this.createOwner(); Content content1 = this.createContent(); Content content2 = this.createContent(); Content content3 = this.createContent(); List<Owner> owners = Arrays.asList(owner1, owner2, owner3); List<Content> contents = Arrays.asList(content1, content2, content3); int mapped = 0; for (int i = 0; i < owners.size(); ++i) { for (int j = 0; j < contents.size(); ++j) { int offset = 0; for (Owner owner : owners) { for (Content content : contents) { if (mapped > offset++) { assertTrue(this.isContentMappedToOwner(content, owner)); } else { assertFalse(this.isContentMappedToOwner(content, owner)); } } } boolean result = this.ownerContentCurator.mapContentToOwner(contents.get(j), owners.get(i)); assertTrue(result); result = this.ownerContentCurator.mapContentToOwner(contents.get(j), owners.get(i)); assertFalse(result); ++mapped; } } }
@Test public void testMapContentToOwnerUnmappedOwner() { Owner owner = new Owner("unmapped"); Content content = this.createContent(); assertThrows(IllegalStateException.class, () -> this.ownerContentCurator.mapContentToOwner(content, owner) ); }
@Test public void testMapContentToOwnerUnmappedContent() { Owner owner = this.createOwner(); Content content = TestUtil.createContent(); assertThrows(IllegalStateException.class, () -> this.ownerContentCurator.mapContentToOwner(content, owner) ); }