diff options
author | Devan Goodwin <dgoodwin@redhat.com> | 2009-12-01 15:08:17 -0400 |
---|---|---|
committer | Devan Goodwin <dgoodwin@redhat.com> | 2009-12-01 15:17:51 -0400 |
commit | bb97c2e64b94c973242aca72edd4cf969b97f3de (patch) | |
tree | 023b8626be16c07978e2d0c25ea76974feb0e8d1 | |
parent | 8e7c85b8ee030de4720ef6eed2faf5c4433d3de2 (diff) | |
download | candlepin-bb97c2e64b94c973242aca72edd4cf969b97f3de.tar.gz candlepin-bb97c2e64b94c973242aca72edd4cf969b97f3de.tar.xz candlepin-bb97c2e64b94c973242aca72edd4cf969b97f3de.zip |
Map the User class to the database.
4 files changed, 88 insertions, 11 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/User.java b/proxy/code/src/org/fedoraproject/candlepin/model/User.java index cbe2395..33a6ab5 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/User.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/User.java @@ -16,6 +16,12 @@ 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.ManyToOne; +import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; @@ -23,28 +29,48 @@ import javax.xml.bind.annotation.XmlTransient; /** * Represents the user. - * TODO: how does this differ from an Owner. + * + * A user is more akin to an account within an owner. (i.e. organization) */ @XmlRootElement @XmlAccessorType(XmlAccessType.PROPERTY) -public class User extends BaseModel { +@Entity +@Table(name="cp_user") +public class User { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long id; + + @ManyToOne private Owner owner; + private String login; + + // TODO: Hash! private String password; + public User() { + } + + public User(Owner ownerIn, String loginIn, String passwordIn) { + owner = ownerIn; + login = loginIn; + password = passwordIn; + } + /** - * @param uuid unique id + * @return the id */ - public User(String uuid) { - super(uuid); + public Long getId() { + return id; } - + /** - * Default ctor + * @param id the id to set */ - public User() { - this(null); + public void setId(Long id) { + this.id = id; } /** diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java new file mode 100644 index 0000000..88af7ff --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/UserTest.java @@ -0,0 +1,45 @@ +/** + * 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.Owner; +import org.fedoraproject.candlepin.model.User; +import org.fedoraproject.candlepin.test.DatabaseTestFixture; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class UserTest extends DatabaseTestFixture { + + @Test + public void testCreate() throws Exception { + String ownerName = "Example Corporation"; + Owner o = new Owner(ownerName); + + String username = "TESTUSER"; + String password = "sekretpassword"; + User user = new User(o, username, password); + + beginTransaction(); + em.persist(o); + em.persist(user); + commitTransaction(); + + User lookedUp = (User)em.find(User.class, user.getId()); + assertEquals(username, lookedUp.getLogin()); + assertEquals(password, lookedUp.getPassword()); + } + +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/UserResource.java b/proxy/code/src/org/fedoraproject/candlepin/resource/UserResource.java index 040cc98..c3e541e 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/resource/UserResource.java +++ b/proxy/code/src/org/fedoraproject/candlepin/resource/UserResource.java @@ -82,8 +82,7 @@ public class UserResource extends BaseResource { public User create(@FormParam("login") String login, @FormParam("password") String password) { System.out.println("login: " + login); System.out.println("password: " + password); - String newuuid = BaseModel.generateUUID(); - User u = new User(newuuid); + User u = new User(); u.setLogin(login); u.setPassword(password); ObjectFactory.get().store(u); diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java index f95e102..d3ff05d 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java +++ b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java @@ -11,6 +11,7 @@ import org.fedoraproject.candlepin.model.Entitlement; 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.util.EntityManagerUtil; import org.junit.After; import org.junit.Before; @@ -46,6 +47,12 @@ public class DatabaseTestFixture { beginTransaction(); } + List<User> users = em.createQuery("from User u"). + getResultList(); + for (User u : users) { + em.remove(u); + } + List<Entitlement> ents = em.createQuery("from Entitlement e"). getResultList(); for (Entitlement e : ents) { |