From ee276a09c0130918ba1a0e5a30780a865f0f2b00 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 2 Dec 2009 14:05:47 -0400 Subject: Fix bad Consumer to Product mapping. Should be ManyToMany, not OneToMany. Doh! --- .../org/fedoraproject/candlepin/model/Consumer.java | 7 ++++--- .../candlepin/model/test/ConsumerTest.java | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'proxy') diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java index 3e3cc66..ecc829e 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java @@ -26,6 +26,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; @@ -72,9 +73,9 @@ public class Consumer { inverseJoinColumns=@JoinColumn(name="CHILD_CONSUMER_ID")) private Set childConsumers; - // TODO: Are we sure we want to track this explicitly? Wouldn't we examine the - // entitlements we're consuming and the products associated to them for this info? - @OneToMany + // Separate mapping because in theory, a consumer could be consuming products they're + // not entitled to. + @ManyToMany @JoinTable(name="cp_consumer_products", joinColumns=@JoinColumn(name="consumer_id"), inverseJoinColumns=@JoinColumn(name="product_id")) diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java index 7fccd33..0ed5364 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java @@ -156,16 +156,14 @@ public class ConsumerTest extends DatabaseTestFixture { public void testConsumerHierarchy() { beginTransaction(); - Consumer child1 = new Consumer("child1asd", owner, consumerType); - child1.setMetadataField("foo6", "bar"); -// child1.addConsumedProduct(rhel); + Consumer child1 = new Consumer("child1", owner, consumerType); + child1.setMetadataField("foo", "bar"); em.persist(child1); commitTransaction(); beginTransaction(); Consumer child2 = new Consumer("child2", owner, consumerType); - child2.setMetadataField("foo87", "bar"); -// child2.addConsumedProduct(rhel); + child2.setMetadataField("foo", "bar"); em.persist(child2); commitTransaction(); @@ -178,5 +176,18 @@ public class ConsumerTest extends DatabaseTestFixture { Consumer lookedUp = (Consumer)em.find(Consumer.class, consumer.getId()); assertEquals(2, lookedUp.getChildConsumers().size()); } + + // This this looks like a stupid test but this was actually failing at one point. :) + @Test + public void testMultipleConsumersSameConsumedProduct() { + beginTransaction(); + + // Default consumer already consumes RHEL: + Consumer child1 = new Consumer("child1", owner, consumerType); + child1.setMetadataField("foo", "bar"); + child1.addConsumedProduct(rhel); + em.persist(child1); + commitTransaction(); + } } -- cgit