diff options
author | Dmitri Dolguikh <ddolguik@redhat.com> | 2009-12-04 14:32:50 -0400 |
---|---|---|
committer | Dmitri Dolguikh <ddolguik@redhat.com> | 2009-12-04 14:32:50 -0400 |
commit | 7870c9b7c62057e737f2fa8dff16cf0f9f472039 (patch) | |
tree | 9f0ba0d68a422174b5b66ece5121247420dc73e3 /proxy | |
parent | 94501c3b433a3e2ef9cfe5e6da49f930204a0c08 (diff) | |
parent | a04a850ef1eb2f625e993d8c36b1a00122b4c023 (diff) | |
download | candlepin-7870c9b7c62057e737f2fa8dff16cf0f9f472039.tar.gz candlepin-7870c9b7c62057e737f2fa8dff16cf0f9f472039.tar.xz candlepin-7870c9b7c62057e737f2fa8dff16cf0f9f472039.zip |
Merge branch 'master' of ssh://git.fedorahosted.org/git/candlepin
Diffstat (limited to 'proxy')
17 files changed, 157 insertions, 60 deletions
diff --git a/proxy/build.xml b/proxy/build.xml index 6bac8d6..f1593cc 100644 --- a/proxy/build.xml +++ b/proxy/build.xml @@ -482,22 +482,9 @@ Running @{banner} ... <delete file="${megajar.jar}" /> <jar destfile="${megajar.jar}"> <fileset dir="${build.dir}/classes"> - <!-- internal is not for publication; tlds go in META-INF; - html go as javadoc elsewhere --> - <exclude name="**/internal/**" /> - <exclude name="**/*.tld" /> - <exclude name="**/*.html" /> <exclude name="**/test/*" /> <exclude name="**/log4j.properties" /> - <exclude name="**/*.conf" /> - <exclude name="**/*.conf.rpmsave" /> - <exclude name="**/test/validation/userCreateForm.xsd" /> </fileset> - <!-- ugh, we can't flatten this like we would with a <copy> tag - or use a mapper, alas --> - <!-- metainf dir="${build.dir}/classes/com/redhat/rhn/frontend/taglibs"> - <include name="*.tld" /> - </metainf --> </jar> </target> @@ -511,6 +498,9 @@ Running @{banner} ... <include name="log4j.properties" /> </classes> <classes dir="${build.dir}/classes"> + <include name="persistence.xml" /> + </classes> + <classes dir="${build.dir}/classes"> <include name="logging.properties" /> </classes> <lib dir="${run.lib.dir}"> @@ -573,20 +563,22 @@ Running @{banner} ... </exec> </target> - <target name="gen-schema" depends="init-taskdefs" description="Generates database schema from Hibernate annotations."> + <target name="gen-schema" depends="init-taskdefs,all" description="Generates database schema from Hibernate annotations."> <property name="dir.genhbm" value="build/schemagen/" /> <delete dir="${dir.genhbm}" /> <mkdir dir="${dir.genhbm}" /> <hibernatetool destdir="${dir.genhbm}"> +<!-- <property key="hibernate.connection.driver_class" value="org.postgresql.Driver"/> <property key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> +--> <classpath> <path location="build/classes"/> </classpath> - <jpaconfiguration persistenceunit="test"/> + <jpaconfiguration persistenceunit="production"/> <hbm2ddl export="false" update="false" diff --git a/proxy/code/src/META-INF/persistence.xml b/proxy/code/src/META-INF/persistence.xml index 47559cb..ee53eba 100644 --- a/proxy/code/src/META-INF/persistence.xml +++ b/proxy/code/src/META-INF/persistence.xml @@ -6,16 +6,30 @@ <persistence-unit name="test" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> - <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/> - <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> + <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> + <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.show_sql" value="true" /> </properties> + </persistence-unit> + + <persistence-unit name="production" transaction-type="RESOURCE_LOCAL"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> + <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/> + <property name="hibernate.connection.url" value="jdbc:postgresql:candlepin"/> + + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="hibernate.connection.username" value="sa"/> + <property name="hibernate.connection.password" value=""/> + <property name="hibernate.show_sql" value="true" /> + </properties> </persistence-unit> diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java index 83f3670..6bc0019 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java @@ -36,6 +36,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * A Consumer is the entity that uses a given Entitlement. It can be a user, @@ -60,9 +61,12 @@ public class Consumer { @ManyToOne @JoinColumn(nullable=false) + @ForeignKey(name="fk_consumer_consumer_type") private ConsumerType type; @ManyToOne + @ForeignKey(name="fk_consumer_owner") + @JoinColumn(nullable=false) private Owner owner; // Consumer hierarchy it meant to be useful to represent the relationship between @@ -73,15 +77,20 @@ public class Consumer { inverseJoinColumns=@JoinColumn(name="CHILD_CONSUMER_ID")) private Set<Consumer> childConsumers; + // Separate mapping because in theory, a consumer could be consuming products they're // not entitled to. @ManyToMany + @ForeignKey(name="fk_consumer_product_consumer_id", + inverseName="fk_consumer_product_product_id") @JoinTable(name="cp_consumer_products", joinColumns=@JoinColumn(name="consumer_id"), inverseJoinColumns=@JoinColumn(name="product_id")) private Set<Product> consumedProducts; @OneToMany + @ForeignKey(name="fk_consumer_product_consumer_id", + inverseName="fk_consumer_produce_product_id") @JoinTable(name="cp_consumer_entitlements", joinColumns=@JoinColumn(name="consumer_id"), inverseJoinColumns=@JoinColumn(name="entitlement_id")) @@ -96,16 +105,14 @@ public class Consumer { this.owner = owner; this.type = type; - this.info = new ConsumerInfo(); - this.info.setConsumer(this); // TODO: ??? + this.info = new ConsumerInfo(this); this.childConsumers = new HashSet<Consumer>(); this.consumedProducts = new HashSet<Product>(); this.entitlements = new HashSet<Entitlement>(); } public Consumer() { - this.info = new ConsumerInfo(); - this.info.setConsumer(this); // TODO: ??? + this.info = new ConsumerInfo(this); this.childConsumers = new HashSet<Consumer>(); this.consumedProducts = new HashSet<Product>(); this.entitlements = new HashSet<Entitlement>(); diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java index 6ea48bc..c1c2eaa 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java @@ -66,6 +66,11 @@ public class ConsumerInfo { metadata = new HashMap<String, String>(); } + public ConsumerInfo(Consumer consumerIn) { + metadata = new HashMap<String, String>(); + consumer = consumerIn; + } + /** * @return the id */ diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerType.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerType.java index ddb5976..143f5d9 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerType.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerType.java @@ -24,7 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement; /** * Represents the type of consumer. * - * TODO: Examples? + * See ProductFactory for some examples. */ @XmlRootElement @XmlAccessorType(XmlAccessType.PROPERTY) diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java index f1614a8..3f7bb94 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java @@ -27,6 +27,9 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; + + /** * Entitlements are documents either signed XML or other certificate which @@ -55,10 +58,12 @@ public class Entitlement { private Long id; @ManyToOne + @ForeignKey(name="fk_entitlement_owner") @JoinColumn(nullable=false) private Owner owner; @ManyToOne + @ForeignKey(name="fk_entitlement_entitlement_pool") @JoinColumn(nullable=false) private EntitlementPool pool; diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java index 71eef9f..9619e2b 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java @@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * Represents a pool of products eligible to be consumed (entitled). @@ -45,10 +46,12 @@ public class EntitlementPool { private Long id; @ManyToOne + @ForeignKey(name="fk_entitlement_pool_owner") @JoinColumn(nullable=false) private Owner owner; @ManyToOne + @ForeignKey(name="fk_entitlement_pool_product") @JoinColumn(nullable=false) private Product product; diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java index 46f8999..6367817 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java @@ -14,8 +14,8 @@ */ package org.fedoraproject.candlepin.model; -import java.util.LinkedList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -29,6 +29,9 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import org.hibernate.annotations.ForeignKey; + + /** * Represents the owner of entitlements. * @@ -48,22 +51,24 @@ public class Owner { @Column(nullable=false) private String name; - // TODO: Remove these transients once the appropriate objects are mapped: - - @Transient - private List<Consumer> consumers; + @OneToMany(mappedBy="owner", targetEntity=Consumer.class) + private Set<Consumer> consumers; // EntitlementPool is the owning side of this relationship. @OneToMany(mappedBy="owner", targetEntity=EntitlementPool.class) - private List<EntitlementPool> entitlementPools; + @ForeignKey(name="fk_user_owner_id") + private Set<EntitlementPool> entitlementPools; - @Transient - private List<User> users; + @OneToMany(mappedBy="owner", targetEntity=User.class) + private Set<User> users; /** * Default constructor. */ public Owner() { + consumers = new HashSet<Consumer>(); + entitlementPools = new HashSet<EntitlementPool>(); + users = new HashSet<User>(); } /** @@ -73,6 +78,10 @@ public class Owner { */ public Owner(String nameIn) { this.name = nameIn; + + consumers = new HashSet<Consumer>(); + entitlementPools = new HashSet<EntitlementPool>(); + users = new HashSet<User>(); } /** @@ -106,37 +115,37 @@ public class Owner { /** * @return the consumers */ - public List<Consumer> getConsumers() { + public Set<Consumer> getConsumers() { return consumers; } /** * @param consumers the consumers to set */ - public void setConsumers(List<Consumer> consumers) { + public void setConsumers(Set<Consumer> consumers) { this.consumers = consumers; } /** * @return the entitlementPools */ - public List<EntitlementPool> getEntitlementPools() { + public Set<EntitlementPool> getEntitlementPools() { return entitlementPools; } /** * @param entitlementPools the entitlementPools to set */ - public void setEntitlementPools(List<EntitlementPool> entitlementPools) { + public void setEntitlementPools(Set<EntitlementPool> entitlementPools) { this.entitlementPools = entitlementPools; } /** * @return the users */ - public List<User> getUsers() { + public Set<User> getUsers() { return users; } /** * @param users the users to set */ - public void setUsers(List<User> users) { + public void setUsers(Set<User> users) { this.users = users; } @@ -147,7 +156,7 @@ public class Owner { public void addUser(User u) { u.setOwner(this); if (this.users == null) { - this.users = new LinkedList<User>(); + this.users = new HashSet<User>(); } this.users.add(u); } @@ -158,9 +167,6 @@ public class Owner { */ public void addConsumer(Consumer c) { c.setOwner(this); - if (this.consumers == null) { - this.consumers = new LinkedList<Consumer>(); - } this.consumers.add(c); } @@ -172,7 +178,7 @@ public class Owner { public void addEntitlementPool(EntitlementPool pool) { pool.setOwner(this); if (this.entitlementPools == null) { - this.entitlementPools = new LinkedList<EntitlementPool>(); + this.entitlementPools = new HashSet<EntitlementPool>(); } this.entitlementPools.add(pool); } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Product.java b/proxy/code/src/org/fedoraproject/candlepin/model/Product.java index 127287c..7eae3dd 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Product.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Product.java @@ -30,6 +30,7 @@ import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; +import org.hibernate.annotations.ForeignKey; /** * Represents a Product that can be consumed and entitled. Products define @@ -47,7 +48,6 @@ public class Product { @GeneratedValue(strategy=GenerationType.AUTO) private Long id; - // TODO: Drop one of these? @Column(nullable=false, unique=true) private String label; @@ -55,6 +55,8 @@ public class Product { private String name; @OneToMany(targetEntity=Product.class, cascade=CascadeType.ALL) + @ForeignKey(name = "fk_product_product_id", + inverseName = "fk_product_child_product_id") @JoinTable(name="cp_product_hierarchy", joinColumns=@JoinColumn(name="PARENT_PRODUCT_ID"), inverseJoinColumns=@JoinColumn(name="CHILD_PRODUCT_ID")) @@ -69,7 +71,6 @@ public class Product { * @param name */ public Product(String label, String name) { - // TODO: Do we want to drop one of these? setLabel(label); setName(name); } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ProductFactory.java b/proxy/code/src/org/fedoraproject/candlepin/model/ProductFactory.java index ca949c9..589cdd0 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ProductFactory.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ProductFactory.java @@ -131,7 +131,7 @@ public class ProductFactory extends ObjectFactory { } /** - * Lookup a ConsumerTYpe by name + * Lookup a ConsumerType by name * @param labelIn to lookup by * @return ConsumerType found */ diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/User.java b/proxy/code/src/org/fedoraproject/candlepin/model/User.java index 33a6ab5..dd67521 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/User.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/User.java @@ -15,17 +15,18 @@ package org.fedoraproject.candlepin.model; import java.util.Formatter; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.hibernate.annotations.ForeignKey; /** * Represents the user. @@ -43,6 +44,8 @@ public class User { private Long id; @ManyToOne + @ForeignKey(name="fk_user_owner_id") + @JoinColumn(nullable=false) private Owner owner; private String login; 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 dc03056..aedd2b3 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java @@ -109,6 +109,7 @@ public class ConsumerTest extends DatabaseTestFixture { assertEquals("bar", lookedUp.getInfo().getMetadataField("foo")); assertEquals("bar1", metadata.get("foo1")); assertEquals("bar1", lookedUp.getInfo().getMetadataField("foo1")); + assertEquals(consumer.getId(), lookedUp.getInfo().getConsumer().getId()); commitTransaction(); } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java index bbef5db..83e6299 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java @@ -15,11 +15,13 @@ package org.fedoraproject.candlepin.model.test; import org.fedoraproject.candlepin.model.Consumer; +import org.fedoraproject.candlepin.model.ConsumerType; import org.fedoraproject.candlepin.model.EntitlementPool; import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.model.Product; import org.fedoraproject.candlepin.model.User; import org.fedoraproject.candlepin.test.DatabaseTestFixture; +import org.fedoraproject.candlepin.test.TestUtil; import java.util.List; @@ -38,9 +40,6 @@ public class OwnerTest extends DatabaseTestFixture { .setParameter("name", ownerName).getSingleResult(); assertNotNull(result); assertEquals(ownerName, result.getName()); -// assertEquals(0, result.getConsumers().size()); -// assertEquals(0, result.getEntitlementPools().size()); -// assertEquals(0, result.getUsers().size()); assertTrue(result.getId() > 0); assertEquals(o.getId(), result.getId()); } @@ -93,4 +92,51 @@ public class OwnerTest extends DatabaseTestFixture { assertEquals(1, owner.getEntitlementPools().size()); } + + @Test + public void bidirectionalConsumers() throws Exception { + beginTransaction(); + Owner o = TestUtil.createOwner(); + ConsumerType consumerType = TestUtil.createConsumerType(); + Consumer c1 = TestUtil.createConsumer(consumerType, o); + Consumer c2 = TestUtil.createConsumer(consumerType, o); + o.addConsumer(c1); + o.addConsumer(c2); + em.persist(o); + em.persist(consumerType); + em.persist(c1); + em.persist(c2); + + commitTransaction(); + + assertEquals(2, o.getConsumers().size()); + + em.clear(); + Owner lookedUp = (Owner)em.find(Owner.class, o.getId()); + assertEquals(2, lookedUp.getConsumers().size()); + } + + @Test + public void bidirectionalUsers() throws Exception { + beginTransaction(); + Owner o = TestUtil.createOwner(); + + User u1 = TestUtil.createUser(o); + User u2 = TestUtil.createUser(o); + + o.addUser(u1); + o.addUser(u2); + em.persist(o); + em.persist(u1); + em.persist(u2); + + commitTransaction(); + + assertEquals(2, o.getUsers().size()); + + em.clear(); + Owner lookedUp = (Owner)em.find(Owner.class, o.getId()); + assertEquals(2, lookedUp.getUsers().size()); + } + } diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java index f4f40b2..82ea14a 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java +++ b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java @@ -72,7 +72,7 @@ public class CertificateResource extends BaseResource { encodedCert = base64cert; String decoded = Base64.base64Decode(base64cert); - System.out.println(decoded); +// System.out.println(decoded); cert = CertificateFactory.read(decoded); addProducts(cert); diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/test/ConsumerResourceTest.java b/proxy/code/src/org/fedoraproject/candlepin/resource/test/ConsumerResourceTest.java index cf4a9d1..3e48974 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/test/ConsumerResourceTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/resource/test/ConsumerResourceTest.java @@ -21,8 +21,10 @@ import org.fedoraproject.candlepin.model.ConsumerInfo; import org.fedoraproject.candlepin.model.ConsumerRepository; import org.fedoraproject.candlepin.model.ConsumerType; import org.fedoraproject.candlepin.model.ConsumerTypeRepository; +import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.resource.ConsumerResource; import org.fedoraproject.candlepin.test.DatabaseTestFixture; +import org.fedoraproject.candlepin.test.TestUtil; import org.junit.Before; import org.junit.Test; @@ -68,9 +70,12 @@ public class ConsumerResourceTest extends DatabaseTestFixture { ConsumerInfo ci = new ConsumerInfo(); ci.setMetadataField("name", newname); - Consumer c = new Consumer(); - c.setName(ci.getMetadataField("name")); - c.setType(standardSystemType); + Owner owner = TestUtil.createOwner(); + beginTransaction(); + em.persist(owner); + commitTransaction(); + + Consumer c = new Consumer(ci.getMetadataField("name"), owner, standardSystemType); c.setInfo(ci); Consumer saved = consumerRepository.create(c); diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java index d3ff05d..79b5593 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java +++ b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java @@ -73,16 +73,16 @@ public class DatabaseTestFixture { em.remove(p); } - List<Owner> owners = em.createQuery("from Owner o").getResultList(); - for (Owner o : owners) { - em.remove(o); - } - List<Consumer> consumers = em.createQuery("from Consumer c").getResultList(); for (Consumer c : consumers) { em.remove(c); } + List<Owner> owners = em.createQuery("from Owner o").getResultList(); + for (Owner o : owners) { + em.remove(o); + } + // List<ConsumerInfo> consumerInfos = em.createQuery("from ConsumerInfo c").getResultList(); // for (ConsumerInfo c : consumerInfos) { // em.remove(c); diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java index 30f8e85..a7b21c0 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java +++ b/proxy/code/src/org/fedoraproject/candlepin/test/TestUtil.java @@ -26,6 +26,7 @@ import org.fedoraproject.candlepin.model.EntitlementPool; import org.fedoraproject.candlepin.model.ObjectFactory; import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.model.Product; +import org.fedoraproject.candlepin.model.User; /** * TestUtil for creating various testing objects. @@ -56,8 +57,11 @@ public class TestUtil { * @return Consumer */ public static Consumer createConsumer() { - return createConsumer(new ConsumerType("test-consumer-type-" + randomInt()), - createOwner()); + return createConsumer(createConsumerType(), createOwner()); + } + + public static ConsumerType createConsumerType() { + return new ConsumerType("test-consumer-type-" + randomInt()); } public static int randomInt() { @@ -84,6 +88,11 @@ public class TestUtil { return e; } + public static User createUser(Owner owner) { + User u = new User(owner, "testuser" + randomInt(), "sekret"); + return u; + } + public static Date createDate(int year, int month, int day) { Calendar cal = Calendar.getInstance(); |