diff options
author | Devan Goodwin <dgoodwin@redhat.com> | 2009-12-02 14:05:47 -0400 |
---|---|---|
committer | Devan Goodwin <dgoodwin@redhat.com> | 2009-12-02 14:05:47 -0400 |
commit | ee276a09c0130918ba1a0e5a30780a865f0f2b00 (patch) | |
tree | c8a75e013b138df44705f7e2818b3a2a56d1d4b2 | |
parent | ce5b41ea6b626d2a41b78b832e44135847ef3c06 (diff) | |
download | candlepin-ee276a09c0130918ba1a0e5a30780a865f0f2b00.tar.gz candlepin-ee276a09c0130918ba1a0e5a30780a865f0f2b00.tar.xz candlepin-ee276a09c0130918ba1a0e5a30780a865f0f2b00.zip |
Fix bad Consumer to Product mapping.
Should be ManyToMany, not OneToMany. Doh!
-rw-r--r-- | proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java | 7 | ||||
-rw-r--r-- | proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java | 21 |
2 files changed, 20 insertions, 8 deletions
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<Consumer> 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(); + } } |