From 0e680936202eba693eaea34bb33d3db37ecd94ef Mon Sep 17 00:00:00 2001 From: Mike McCune Date: Thu, 23 Jul 2009 11:19:04 -0700 Subject: renaming Org -> Owner --- .../fedoraproject/candlepin/api/ApiHandler.java | 12 +-- .../org/fedoraproject/candlepin/api/OrgApi.java | 30 ------ .../org/fedoraproject/candlepin/api/OwnerApi.java | 30 ++++++ .../fedoraproject/candlepin/api/test/ApiTest.java | 16 +-- .../candlepin/api/test/ConsumerApiTest.java | 4 +- .../fedoraproject/candlepin/model/Consumer.java | 44 ++++++-- .../candlepin/model/ConsumerInfo.java | 53 ++++++--- .../fedoraproject/candlepin/model/Entitlement.java | 10 +- .../candlepin/model/EntitlementPool.java | 14 +-- .../candlepin/model/ObjectFactory.java | 8 +- .../candlepin/model/Organization.java | 119 --------------------- .../org/fedoraproject/candlepin/model/Owner.java | 119 +++++++++++++++++++++ .../org/fedoraproject/candlepin/model/User.java | 14 +-- .../candlepin/model/test/ConsumerTest.java | 12 ++- .../candlepin/model/test/ObjectFactoryTest.java | 34 +++--- .../candlepin/model/test/OrganizationTest.java | 89 --------------- .../candlepin/model/test/OwnerTest.java | 89 +++++++++++++++ .../candlepin/model/test/TestUtil.java | 10 +- 18 files changed, 385 insertions(+), 322 deletions(-) delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/api/OrgApi.java create mode 100644 proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/Organization.java create mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/Owner.java delete mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/test/OrganizationTest.java create mode 100644 proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java (limited to 'proxy/code/src') diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/ApiHandler.java b/proxy/code/src/org/fedoraproject/candlepin/api/ApiHandler.java index e7dab91..0aec7c5 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/ApiHandler.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/ApiHandler.java @@ -3,7 +3,7 @@ package org.fedoraproject.candlepin.api; import org.apache.log4j.Logger; import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Organization; +import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.model.User; import java.util.HashSet; @@ -52,16 +52,16 @@ public class ApiHandler { } } - /** Organizations */ + /** Owners */ - /** Fetch an org + /** Fetch an owner * */ - public Organization getOrg(String authToken, String uuid) { + public Owner getOwner(String authToken, String uuid) { checkToken(authToken); logger.debug("getOrg(String) - start: " + uuid); - Organization retval = (Organization) ObjectFactory.get() - .lookupByUUID(Organization.class, uuid); + Owner retval = (Owner) ObjectFactory.get() + .lookupByUUID(Owner.class, uuid); if (logger.isDebugEnabled()) { logger.debug("getOrg(String) - end. returning: " + retval); } diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/OrgApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/OrgApi.java deleted file mode 100644 index d33c2ea..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/api/OrgApi.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2008 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package org.fedoraproject.candlepin.api; - -import org.fedoraproject.candlepin.model.Organization; - -import javax.ws.rs.Path; - -@Path("/org") -public class OrgApi extends BaseApi { - - @Override - protected Class getApiClass() { - return Organization.class; - } - - -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java new file mode 100644 index 0000000..737702c --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2008 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package org.fedoraproject.candlepin.api; + +import org.fedoraproject.candlepin.model.Owner; + +import javax.ws.rs.Path; + +@Path("/owner") +public class OwnerApi extends BaseApi { + + @Override + protected Class getApiClass() { + return Owner.class; + } + + +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/test/ApiTest.java b/proxy/code/src/org/fedoraproject/candlepin/api/test/ApiTest.java index 6ab1b46..ca88bd7 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/test/ApiTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/test/ApiTest.java @@ -4,10 +4,10 @@ package org.fedoraproject.candlepin.api.test; import org.fedoraproject.candlepin.api.ApiHandler; -import org.fedoraproject.candlepin.api.OrgApi; +import org.fedoraproject.candlepin.api.OwnerApi; import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Organization; +import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.model.User; import junit.framework.TestCase; @@ -32,8 +32,8 @@ public class ApiTest extends TestCase { assertNotNull(token); } - public void testLookupOrg() throws Exception { - Organization o = new Organization(BaseModel.generateUUID()); + public void testLookupOwner() throws Exception { + Owner o = new Owner(BaseModel.generateUUID()); ObjectFactory.get().store(o); User u = new User(); @@ -43,16 +43,16 @@ public class ApiTest extends TestCase { String token = ApiHandler.get().login(u.getLogin(), u.getPassword()); - OrgApi oapi = new OrgApi(); - Organization lookedup = (Organization) oapi.get("BAD-UUID-NOTFOUND"); + OwnerApi oapi = new OwnerApi(); + Owner lookedup = (Owner) oapi.get("BAD-UUID-NOTFOUND"); assertNull(lookedup); - lookedup = ApiHandler.get().getOrg(token, o.getUuid()); + lookedup = ApiHandler.get().getOwner(token, o.getUuid()); assertNotNull(lookedup); // Check bad token boolean failed = false; try { - lookedup = ApiHandler.get().getOrg("BAD-TOKEN", o.getUuid()); + lookedup = ApiHandler.get().getOwner("BAD-TOKEN", o.getUuid()); } catch (Exception e) { failed = true; } diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/test/ConsumerApiTest.java b/proxy/code/src/org/fedoraproject/candlepin/api/test/ConsumerApiTest.java index a8eb305..452d399 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/test/ConsumerApiTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/test/ConsumerApiTest.java @@ -19,8 +19,6 @@ import com.sun.jersey.api.representation.Form; import org.fedoraproject.candlepin.api.ConsumerApi; import org.fedoraproject.candlepin.model.Consumer; import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Organization; -import org.fedoraproject.candlepin.model.test.TestUtil; import junit.framework.TestCase; @@ -33,7 +31,7 @@ public class ConsumerApiTest extends TestCase { public void testCreateConsumer() throws Exception { String newname = "test-consumer-" + System.currentTimeMillis(); - Organization o = TestUtil.createOrg(); + ConsumerApi capi = new ConsumerApi(); Form f = new Form(); f.add("name", newname); diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java index 420ad33..be567e7 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Consumer.java @@ -14,6 +14,7 @@ */ package org.fedoraproject.candlepin.model; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -27,7 +28,7 @@ import javax.xml.bind.annotation.XmlTransient; public class Consumer extends BaseModel { - private Organization organization; + private Owner owner; private Consumer parent; private List consumedProducts; private ConsumerInfo info; @@ -37,6 +38,8 @@ public class Consumer extends BaseModel { */ public Consumer() { this(null); + this.info = new ConsumerInfo(); + this.info.setParent(this); } /** @@ -44,6 +47,8 @@ public class Consumer extends BaseModel { */ public Consumer(String uuid) { super(uuid); + this.info = new ConsumerInfo(); + this.info.setParent(this); } /** @@ -98,18 +103,18 @@ public class Consumer extends BaseModel { } /** - * @return the organization + * @return the owner */ @XmlTransient - public Organization getOrganization() { - return organization; + public Owner getOwner() { + return owner; } /** - * @param organization the organization to set + * @param owner the owner to set */ - public void setOrganization(Organization organization) { - this.organization = organization; + public void setOwner(Owner owner) { + this.owner = owner; } /** @@ -148,5 +153,30 @@ public class Consumer extends BaseModel { public void setInfo(ConsumerInfo infoIn) { info = infoIn; } + + /** + * Set a metadata field + * @param name to set + * @param value to set + */ + public void setMetadataField(String name, String value) { + if (this.getInfo().getMetadata() == null) { + this.getInfo().setMetadata(new HashMap()); + } + this.getInfo().getMetadata().put(name, value); + } + + /** + * Get a metadata field value + * @param name of field to fetch + * @return String field value. + */ + public String getMetadataField(String name) { + if (this.getInfo().getMetadata() != null) { + return getInfo().getMetadata().get(name); + } + return null; + } + } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java index bd056cf..5d582c6 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java @@ -14,6 +14,7 @@ */ package org.fedoraproject.candlepin.model; +import java.util.HashMap; import java.util.Map; @@ -21,7 +22,7 @@ public class ConsumerInfo { private Consumer parent; private String type; - private Map properties; + private Map metadata; /** * @return Returns the parent. @@ -38,30 +39,56 @@ public class ConsumerInfo { } /** - * @return Returns the properties. + * @return Returns the type. */ - public Map getProperties() { - return properties; + public String getType() { + return type; + } + + /** + * @param typeIn The type to set. + */ + public void setType(String typeIn) { + type = typeIn; } + /** - * @param propertiesIn The properties to set. + * @return Returns the metadata. */ - public void setProperties(Map propertiesIn) { - properties = propertiesIn; + public Map getMetadata() { + return metadata; } + /** - * @return Returns the type. + * @param metadataIn The metadata to set. */ - public String getType() { - return type; + public void setMetadata(Map metadataIn) { + metadata = metadataIn; } /** - * @param typeIn The type to set. + * Set a metadata field + * @param name to set + * @param value to set */ - public void setType(String typeIn) { - type = typeIn; + public void setMetadataField(String name, String value) { + if (this.metadata == null) { + metadata = new HashMap(); + } + + } + + /** + * Get a metadata field value + * @param name of field to fetch + * @return String field value. + */ + public String getMetadataField(String name) { + if (this.metadata != null) { + return metadata.get(name); + } + return null; } } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java index 4bd4d92..cba25ae 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java @@ -25,7 +25,7 @@ import javax.xml.bind.annotation.XmlTransient; @XmlAccessorType(XmlAccessType.PROPERTY) public class Entitlement extends BaseModel { - private Organization org; + private Owner owner; private List childEntitlements; /** @@ -46,15 +46,15 @@ public class Entitlement extends BaseModel { * @return the org */ @XmlTransient - public Organization getOrg() { - return org; + public Owner getOwner() { + return owner; } /** * @param org the org to set */ - public void setOrg(Organization org) { - this.org = org; + public void setOwner(Owner ownerIn) { + this.owner = ownerIn; } /** diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java index 1da671a..ce5918a 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java @@ -18,7 +18,7 @@ import java.util.Date; public class EntitlementPool extends BaseModel { - private Organization organization; + private Owner owner; private Product product; private long maxMembers; private long currentMembers; @@ -111,17 +111,17 @@ public class EntitlementPool extends BaseModel { } /** - * @return the organization + * @return the owner */ - public Organization getOrganization() { - return organization; + public Owner getOwner() { + return owner; } /** - * @param organization the organization to set + * @param owner the owner to set */ - public void setOrganization(Organization organization) { - this.organization = organization; + public void setOwner(Owner owner) { + this.owner = owner; } } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java b/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java index 16e0a47..509c6b3 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ObjectFactory.java @@ -49,7 +49,7 @@ public class ObjectFactory { * @deprecated demo method */ private void initMockObjects() { - Organization org = new Organization(BaseModel.generateUUID()); + Owner org = new Owner(BaseModel.generateUUID()); org.setName("test-org"); // Product Product rhel = new Product(BaseModel.generateUUID()); @@ -64,7 +64,7 @@ public class ObjectFactory { // Consumer Consumer c = new Consumer(BaseModel.generateUUID()); c.setName("fake-consumer-i386"); - c.setOrganization(org); + c.setOwner(org); org.addConsumer(c); c.addConsumedProduct(rhel); @@ -97,9 +97,9 @@ public class ObjectFactory { } /** - * Lookup an Organization by UUID + * Lookup an Owner by UUID * @param uuid to lookup - * @return Organization + * @return Owner */ public BaseModel lookupByUUID(Class clazz, String uuid) { return (BaseModel) lookupByFieldName(clazz, "uuid", uuid); diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java b/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java deleted file mode 100644 index 5e128f4..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * Copyright (c) 2009 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -package org.fedoraproject.candlepin.model; - -import java.util.LinkedList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -@XmlAccessorType(XmlAccessType.PROPERTY) -public class Organization extends BaseModel { - - private List consumers; - private List entitlementPools; - private List users; - - /** - * @param uuid - */ - public Organization(String uuid) { - super(uuid); - } - - /** - * Default - */ - public Organization() { - } - - /** - * @return the consumers - */ - public List getConsumers() { - return consumers; - } - /** - * @param consumers the consumers to set - */ - public void setConsumers(List consumers) { - this.consumers = consumers; - } - /** - * @return the entitlementPools - */ - public List getEntitlementPools() { - return entitlementPools; - } - /** - * @param entitlementPools the entitlementPools to set - */ - public void setEntitlementPools(List entitlementPools) { - this.entitlementPools = entitlementPools; - } - /** - * @return the users - */ - public List getUsers() { - return users; - } - /** - * @param users the users to set - */ - public void setUsers(List users) { - this.users = users; - } - - /** - * Add a user. - * @param u to add to this org. - */ - public void addUser(User u) { - u.setOrganization(this); - if (this.users == null) { - this.users = new LinkedList(); - } - this.users.add(u); - } - - public void addConsumer(Consumer c) { - c.setOrganization(this); - if (this.consumers == null) { - this.consumers = new LinkedList(); - } - this.consumers.add(c); - - } - - public void addEntitlementPool(EntitlementPool pool) { - pool.setOrganization(this); - if (this.entitlementPools == null) { - this.entitlementPools = new LinkedList(); - } - this.entitlementPools.add(pool); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return "Organization [getName()=" + getName() + ", getUuid()=" - + getUuid() + "]"; - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java new file mode 100644 index 0000000..16b1f56 --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java @@ -0,0 +1,119 @@ +/** + * Copyright (c) 2009 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package org.fedoraproject.candlepin.model; + +import java.util.LinkedList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) +public class Owner extends BaseModel { + + private List consumers; + private List entitlementPools; + private List users; + + /** + * @param uuid + */ + public Owner(String uuid) { + super(uuid); + } + + /** + * Default + */ + public Owner() { + } + + /** + * @return the consumers + */ + public List getConsumers() { + return consumers; + } + /** + * @param consumers the consumers to set + */ + public void setConsumers(List consumers) { + this.consumers = consumers; + } + /** + * @return the entitlementPools + */ + public List getEntitlementPools() { + return entitlementPools; + } + /** + * @param entitlementPools the entitlementPools to set + */ + public void setEntitlementPools(List entitlementPools) { + this.entitlementPools = entitlementPools; + } + /** + * @return the users + */ + public List getUsers() { + return users; + } + /** + * @param users the users to set + */ + public void setUsers(List users) { + this.users = users; + } + + /** + * Add a user. + * @param u to add to this org. + */ + public void addUser(User u) { + u.setOwner(this); + if (this.users == null) { + this.users = new LinkedList(); + } + this.users.add(u); + } + + public void addConsumer(Consumer c) { + c.setOwner(this); + if (this.consumers == null) { + this.consumers = new LinkedList(); + } + this.consumers.add(c); + + } + + public void addEntitlementPool(EntitlementPool pool) { + pool.setOwner(this); + if (this.entitlementPools == null) { + this.entitlementPools = new LinkedList(); + } + this.entitlementPools.add(pool); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "Owner [getName()=" + getName() + ", getUuid()=" + + getUuid() + "]"; + } +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/User.java b/proxy/code/src/org/fedoraproject/candlepin/model/User.java index 0cbf3d5..8960484 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/User.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/User.java @@ -25,7 +25,7 @@ import javax.xml.bind.annotation.XmlTransient; @XmlAccessorType(XmlAccessType.PROPERTY) public class User extends BaseModel { - private Organization organization; + private Owner owner; private String login; private String password; @@ -68,17 +68,17 @@ public class User extends BaseModel { this.password = password; } /** - * @return the organization + * @return the owner */ @XmlTransient - public Organization getOrganization() { - return organization; + public Owner getOwner() { + return owner; } /** - * @param organization the organization to set + * @param owner the owner to set */ - public void setOrganization(Organization organization) { - this.organization = organization; + public void setOwner(Owner owner) { + this.owner = owner; } public String toString() { 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 d4b2e85..f9ebccf 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ConsumerTest.java @@ -16,7 +16,7 @@ package org.fedoraproject.candlepin.model.test; import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.Consumer; -import org.fedoraproject.candlepin.model.Organization; +import org.fedoraproject.candlepin.model.Owner; import org.fedoraproject.candlepin.model.Product; import junit.framework.TestCase; @@ -25,7 +25,7 @@ import junit.framework.TestCase; public class ConsumerTest extends TestCase { public void testConsumedProduct() throws Exception { - Organization o = TestUtil.createOrg(); + Owner o = TestUtil.createOwner(); Product rhel = new Product(BaseModel.generateUUID()); rhel.setName("Red Hat Enterprise Linux"); @@ -36,4 +36,12 @@ public class ConsumerTest extends TestCase { } + + public void testProperties() { + Owner o = TestUtil.createOwner(); + Consumer c = TestUtil.createConsumer(o); + c.setMetadataField("cpu", "2"); + + assertEquals(c.getMetadataField("cpu"), "2"); + } } 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 2439356..129908a 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/ObjectFactoryTest.java @@ -16,7 +16,7 @@ package org.fedoraproject.candlepin.model.test; import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Organization; +import org.fedoraproject.candlepin.model.Owner; import java.util.List; @@ -41,12 +41,12 @@ public class ObjectFactoryTest extends TestCase { List l = ObjectFactory.get().listObjectsByClass(Object.class); assertNull(l); - l = ObjectFactory.get().listObjectsByClass(Organization.class); + l = ObjectFactory.get().listObjectsByClass(Owner.class); assertNotNull(l); assertFalse(l.isEmpty()); Object o = l.get(0); assertNotNull(o); - assertEquals(o.getClass(), Organization.class); + assertEquals(o.getClass(), Owner.class); } public void testStore() { @@ -67,28 +67,28 @@ public class ObjectFactoryTest extends TestCase { public void testLookupByUUID() { String uuid = BaseModel.generateUUID(); - assertNull(ObjectFactory.get().lookupByUUID(Organization.class, uuid)); + assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid)); - Organization org = new Organization(uuid); - org.setName("unit-test-org"); - ObjectFactory.get().store(org); - Object o = ObjectFactory.get().lookupByUUID(Organization.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(), Organization.class); - assertEquals(((Organization)o).getUuid(), org.getUuid()); + assertEquals(o.getClass(), Owner.class); + assertEquals(((Owner)o).getUuid(), owner.getUuid()); } public void testLookupByFieldName() { String uuid = BaseModel.generateUUID(); - assertNull(ObjectFactory.get().lookupByUUID(Organization.class, uuid)); + assertNull(ObjectFactory.get().lookupByUUID(Owner.class, uuid)); - Organization org = new Organization(uuid); - org.setName("unit-test-org"); - ObjectFactory.get().store(org); + Owner owner = new Owner(uuid); + owner.setName("unit-test-org"); + ObjectFactory.get().store(owner); - Organization o2 = (Organization) ObjectFactory.get().lookupByFieldName( - Organization.class, "uuid", uuid); + Owner o2 = (Owner) ObjectFactory.get().lookupByFieldName( + Owner.class, "uuid", uuid); assertNotNull(o2); - assertEquals(org, o2); + assertEquals(owner, o2); } } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/OrganizationTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/OrganizationTest.java deleted file mode 100644 index 29172fa..0000000 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/OrganizationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (c) 2009 Red Hat, Inc. - * - * This software is licensed to you under the GNU General Public License, - * version 2 (GPLv2). There is NO WARRANTY for this software, express or - * implied, including the implied warranties of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 - * along with this software; if not, see - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. - * - * Red Hat trademarks are not licensed under GPLv2. No permission is - * granted to use or replicate Red Hat trademarks that are incorporated - * in this software or its documentation. - */ -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.Organization; -import org.fedoraproject.candlepin.model.Product; -import org.fedoraproject.candlepin.model.User; - -import java.util.List; - -import junit.framework.TestCase; - -/** - * - * - */ -public class OrganizationTest extends TestCase { - - - public void testOrg() throws Exception { - Organization o = new Organization(BaseModel.generateUUID()); - assertNotNull(o); - } - - public void testLookup() throws Exception { - - Organization o = TestUtil.createOrg(); - String lookedUp = o.getUuid(); - o = (Organization) ObjectFactory.get(). - lookupByUUID(Organization.class, lookedUp); - assertNotNull(o); - } - - public void testList() throws Exception { - for (int i = 0; i < 10; i++) { - TestUtil.createOrg(); - } - - List orgs = ObjectFactory.get().listObjectsByClass(Organization.class); - assertNotNull(orgs); - assertTrue(orgs.size() >= 10); - } - - public void testObjectRelationships() throws Exception { - Organization org = new Organization(BaseModel.generateUUID()); - org.setName("test-org"); - // Product - Product rhel = new Product(BaseModel.generateUUID()); - rhel.setName("Red Hat Enterprise Linux"); - - // User - User u = new User(); - u.setLogin("test-login"); - u.setPassword("redhat"); - org.addUser(u); - assertEquals(1, org.getUsers().size()); - - // Consumer - Consumer c = new Consumer(BaseModel.generateUUID()); - c.setOrganization(org); - org.addConsumer(c); - c.addConsumedProduct(rhel); - assertEquals(1, org.getConsumers().size()); - assertEquals(1, c.getConsumedProducts().size()); - - // EntitlementPool - EntitlementPool pool = new EntitlementPool(BaseModel.generateUUID()); - org.addEntitlementPool(pool); - pool.setProduct(rhel); - assertEquals(1, org.getEntitlementPools().size()); - - } -} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java new file mode 100644 index 0000000..75138e1 --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/OwnerTest.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2009 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +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; + +import java.util.List; + +import junit.framework.TestCase; + +/** + * + * + */ +public class OwnerTest extends TestCase { + + + public void testOwner() throws Exception { + Owner o = new Owner(BaseModel.generateUUID()); + assertNotNull(o); + } + + 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 testList() throws Exception { + for (int i = 0; i < 10; i++) { + TestUtil.createOwner(); + } + + List orgs = ObjectFactory.get().listObjectsByClass(Owner.class); + assertNotNull(orgs); + assertTrue(orgs.size() >= 10); + } + + public void testObjectRelationships() throws Exception { + Owner owner = new Owner(BaseModel.generateUUID()); + owner.setName("test-owner"); + // Product + Product rhel = new Product(BaseModel.generateUUID()); + rhel.setName("Red Hat Enterprise Linux"); + + // User + User u = new User(); + u.setLogin("test-login"); + u.setPassword("redhat"); + owner.addUser(u); + assertEquals(1, owner.getUsers().size()); + + // Consumer + Consumer c = new Consumer(BaseModel.generateUUID()); + c.setOwner(owner); + owner.addConsumer(c); + c.addConsumedProduct(rhel); + assertEquals(1, owner.getConsumers().size()); + assertEquals(1, c.getConsumedProducts().size()); + + // EntitlementPool + EntitlementPool pool = new EntitlementPool(BaseModel.generateUUID()); + owner.addEntitlementPool(pool); + pool.setProduct(rhel); + assertEquals(1, owner.getEntitlementPools().size()); + + } +} 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 2175863..7e691ef 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/TestUtil.java @@ -17,23 +17,23 @@ package org.fedoraproject.candlepin.model.test; import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.Consumer; import org.fedoraproject.candlepin.model.ObjectFactory; -import org.fedoraproject.candlepin.model.Organization; +import org.fedoraproject.candlepin.model.Owner; public class TestUtil { - public static Organization createOrg() { + public static Owner createOwner() { String lookedUp = BaseModel.generateUUID(); - Organization o = new Organization(); + Owner o = new Owner(); o.setUuid(lookedUp); ObjectFactory.get().store(o); return o; } - public static Consumer createConsumer(Organization org) { + public static Consumer createConsumer(Owner owner) { Consumer c = new Consumer(BaseModel.generateUUID()); - c.setOrganization(org); + c.setOwner(owner); ObjectFactory.get().store(c); return c; } -- cgit