OwnerProductCurator extends AbstractHibernateCurator<OwnerProduct> { @Transactional public boolean mapProductToOwner(Product product, Owner owner) { if (!this.isProductMappedToOwner(product, owner)) { this.create(new OwnerProduct(owner, product)); return true; } return false; } OwnerProductCurator(); @Transactional OwnerProduct getOwnerProductByProductId(Owner owner, String productId); Product getProductById(Owner owner, String productId); @Transactional Product getProductById(String ownerId, String productId); @Transactional Product getProductByIdUsingOwnerKey(String ownerKey, String productId); CandlepinQuery<Owner> getOwnersByProduct(Product product); CandlepinQuery<Owner> getOwnersByProduct(String productId); Collection<String> getProductUuidsByOwner(Owner owner); Collection<String> getProductUuidsByOwner(String ownerId); CandlepinQuery<Product> getProductsByOwner(Owner owner); CandlepinQuery<Product> getProductsByOwner(String ownerId); CandlepinQuery<Product> getProductsByIds(Owner owner, Collection<String> productIds); CandlepinQuery<Product> getProductsByIds(String ownerId, Collection<String> productIds); CandlepinQuery<Product> getProductsByIdsUsingOwnerKey(String ownerKey,
        Collection<String> productIds); @Transactional long getOwnerCount(Product product); @Transactional boolean productExists(Owner owner, String productId); @Transactional Set<String> filterUnknownProductIds(Owner owner, Collection<String> productIds); @Transactional boolean isProductMappedToOwner(Product product, Owner owner); @Transactional boolean mapProductToOwner(Product product, Owner owner); @Transactional int mapProductToOwners(Product product, Owner... owners); @Transactional int mapOwnerToProducts(Owner owner, Product... products); @Transactional boolean removeOwnerFromProduct(Product product, Owner owner); @Transactional int clearOwnersForProduct(Product product); @Transactional int clearProductsForOwner(Owner owner); CandlepinQuery<Product> getOrphanedProducts(); @SuppressWarnings("checkstyle:indentation") CandlepinQuery<Product> getProductsByVersions(Owner owner, Map<String, Integer> productVersions); @Transactional void updateOwnerProductReferences(Owner owner, Map<String, String> productUuidMap); @Transactional @SuppressWarnings("checkstyle:indentation") void removeOwnerProductReferences(Owner owner, Collection<String> productUuids);  }
@Test public void testMapProductToOwner() { Owner owner1 = this.createOwner(); Owner owner2 = this.createOwner(); Owner owner3 = this.createOwner(); Product product1 = this.createProduct(); Product product2 = this.createProduct(); Product product3 = this.createProduct(); List<Owner> owners = Arrays.asList(owner1, owner2, owner3); List<Product> products = Arrays.asList(product1, product2, product3); int mapped = 0; for (int i = 0; i < owners.size(); ++i) { for (int j = 0; j < products.size(); ++j) { int offset = 0; for (Owner owner : owners) { for (Product product : products) { if (mapped > offset++) { assertTrue(this.isProductMappedToOwner(product, owner)); } else { assertFalse(this.isProductMappedToOwner(product, owner)); } } } boolean result = this.ownerProductCurator.mapProductToOwner(products.get(j), owners.get(i)); assertTrue(result); result = this.ownerProductCurator.mapProductToOwner(products.get(j), owners.get(i)); assertFalse(result); ++mapped; } } }
@Test public void testMapProductToOwnerUnmappedOwner() { Owner owner = new Owner("unmapped"); Product product = this.createProduct(); assertThrows(IllegalStateException.class, () -> this.ownerProductCurator.mapProductToOwner(product, owner) ); }
@Test public void testMapProductToOwnerUnmappedProduct() { Owner owner = this.createOwner(); Product product = TestUtil.createProduct(); assertThrows(IllegalStateException.class, () -> this.ownerProductCurator.mapProductToOwner(product, owner) ); }