summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2009-11-24 15:46:38 -0400
committerDevan Goodwin <dgoodwin@redhat.com>2009-11-24 15:46:38 -0400
commit9c58ed07bccf729ffe575cbfb3af3643365abc39 (patch)
tree840956b1b734563ad4c1f2c6d7a3da0c074f014a
parent2aa9936d8ac1434a6bc870c0f4779e6785488c71 (diff)
downloadcandlepin-9c58ed07bccf729ffe575cbfb3af3643365abc39.tar.gz
candlepin-9c58ed07bccf729ffe575cbfb3af3643365abc39.tar.xz
candlepin-9c58ed07bccf729ffe575cbfb3af3643365abc39.zip
Annotate Owner object for database mapping.
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java2
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Owner.java70
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java55
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java52
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java3
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java1
6 files changed, 118 insertions, 65 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java b/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java
index 7d2e27b..eeaf8ec 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java
@@ -50,7 +50,7 @@ public class ObjectFactory {
* @deprecated demo method
*/
private void initMockObjects() {
- Owner org = new Owner(BaseModel.generateUUID());
+ Owner org = new Owner();
org.setName("test-org");
// User
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
index 8bc43de..f73d87f 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
@@ -17,35 +17,87 @@ package org.fedoraproject.candlepin.model;
import java.util.LinkedList;
import java.util.List;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
- * Represents the owner of entitlements
+ * Represents the owner of entitlements.
+ *
+ * This is akin to an organization, whereas a User is an individual account within that
+ * organization.
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
-public class Owner extends BaseModel {
+@Entity
+@Table(name="cp_owner")
+public class Owner {
+ @Id
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ private Long id;
+
+ private String name;
+
+ @Transient
private List<Consumer> consumers;
+
+ @Transient
private List<EntitlementPool> entitlementPools;
+
+ @Transient
private List<User> users;
/**
- * @param uuid unique id for the owner
+ * Default constructor.
*/
- public Owner(String uuid) {
- super(uuid);
+ public Owner() {
}
/**
- * Default
+ * Constructor with required parameters.
+ *
+ * @param name Owner's name.
*/
- public Owner() {
+ public Owner(String nameIn) {
+ this.name = nameIn;
}
/**
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
* @return the consumers
*/
public List<Consumer> getConsumers() {
@@ -124,7 +176,7 @@ public class Owner extends BaseModel {
*/
@Override
public String toString() {
- return "Owner [getName()=" + getName() + ", getUuid()=" +
- getUuid() + "]";
+ return "Owner [name = " + getName() + ", id = " +
+ getId() + "]";
}
}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java
index 8bd66f1..f0926ab 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java
@@ -14,7 +14,6 @@
*/
package org.fedoraproject.candlepin.model.test;
-import org.fedoraproject.candlepin.model.BaseModel;
import org.fedoraproject.candlepin.model.ObjectFactory;
import org.fedoraproject.candlepin.model.Owner;
@@ -71,32 +70,32 @@ public class ObjectFactoryTest {
assertEquals(l, l2);
}
- @Test
- public void testLookupByUUID() {
- String uuid = BaseModel.generateUUID();
- assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid));
-
- Owner owner = new Owner(uuid);
- owner.setName("unit-test-owner");
- ObjectFactory.get().store(owner);
- Object o = ObjectFactory.get().lookupByUUID(Owner.class, uuid);
- assertNotNull(o);
- assertEquals(o.getClass(), Owner.class);
- assertEquals(((Owner)o).getUuid(), owner.getUuid());
- }
+// @Test
+// public void testLookupByUUID() {
+// String uuid = BaseModel.generateUUID();
+// assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid));
+//
+// Owner owner = new Owner(uuid);
+// owner.setName("unit-test-owner");
+// ObjectFactory.get().store(owner);
+// Object o = ObjectFactory.get().lookupByUUID(Owner.class, uuid);
+// assertNotNull(o);
+// assertEquals(o.getClass(), Owner.class);
+// assertEquals(((Owner)o).getUuid(), owner.getUuid());
+// }
- @Test
- public void testLookupByFieldName() {
- String uuid = BaseModel.generateUUID();
- assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid));
-
- Owner owner = new Owner(uuid);
- owner.setName("unit-test-org");
- ObjectFactory.get().store(owner);
-
- Owner o2 = (Owner) ObjectFactory.get().lookupByFieldName(
- Owner.class, "uuid", uuid);
- assertNotNull(o2);
- assertEquals(owner, o2);
- }
+// @Test
+// public void testLookupByFieldName() {
+// String uuid = BaseModel.generateUUID();
+// assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid));
+//
+// Owner owner = new Owner(uuid);
+// owner.setName("unit-test-org");
+// ObjectFactory.get().store(owner);
+//
+// Owner o2 = (Owner) ObjectFactory.get().lookupByFieldName(
+// Owner.class, "uuid", uuid);
+// assertNotNull(o2);
+// assertEquals(owner, o2);
+// }
}
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 abfce82..fe89b50 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java
@@ -17,7 +17,6 @@ package org.fedoraproject.candlepin.model.test;
import org.fedoraproject.candlepin.model.BaseModel;
import org.fedoraproject.candlepin.model.Consumer;
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;
@@ -27,43 +26,46 @@ import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
-/**
- *
- *
- */
-public class OwnerTest {
+public class OwnerTest extends ModelTestFixture {
@Test
- public void testOwner() throws Exception {
- Owner o = new Owner(BaseModel.generateUUID());
- assertNotNull(o);
- }
-
- @Test
- public void testLookup() throws Exception {
-
- Owner o = TestUtil.createOwner();
- String lookedUp = o.getUuid();
- o = (Owner) ObjectFactory.get().
- lookupByUUID(Owner.class, lookedUp);
- assertNotNull(o);
+ public void testCreate() throws Exception {
+ String ownerName = "Example Corporation";
+ Owner o = new Owner(ownerName);
+ persistAndCommit(o);
+ Owner result = (Owner)em.createQuery(
+ "select o from Owner o where o.name = :name")
+ .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());
}
@Test
public void testList() throws Exception {
+ em.getTransaction().begin();
+
+ List<Owner> orgs = em.createQuery("select o from Owner as o")
+ .getResultList();
+ int beforeCount = orgs.size();
+
for (int i = 0; i < 10; i++) {
- TestUtil.createOwner();
+ em.persist(new Owner("Corp " + i));
}
- List orgs = ObjectFactory.get().listObjectsByClass(Owner.class);
- assertNotNull(orgs);
- assertTrue(orgs.size() >= 10);
+ orgs = em.createQuery("select o from Owner as o")
+ .getResultList();
+ int afterCount = orgs.size();
+ assertEquals(10, afterCount - beforeCount);
}
@Test
public void testObjectRelationships() throws Exception {
- Owner owner = new Owner(BaseModel.generateUUID());
- owner.setName("test-owner");
+ Owner owner = new Owner("test-owner");
// Product
Product rhel = new Product(BaseModel.generateUUID());
rhel.setName("Red Hat Enterprise Linux");
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java
index b2e2ad3..7ad0bb6 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java
@@ -26,10 +26,11 @@ public class TestUtil {
private TestUtil() {
}
+ @Deprecated
public static Owner createOwner() {
String lookedUp = BaseModel.generateUUID();
Owner o = new Owner();
- o.setUuid(lookedUp);
+// o.setUuid(lookedUp);
ObjectFactory.get().store(o);
return o;
}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
index bffd616..f4f40b2 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
@@ -124,7 +124,6 @@ public class CertificateResource extends BaseResource {
owner = new Owner();
owner.setName(cert.getOwner());
owner = (Owner) ObjectFactory.get().store(owner);
- System.out.println(owner.getUuid());
}
// get the product the cert is for (and the channel families