diff options
| author | jesus m. rodriguez <jesusr@redhat.com> | 2009-07-09 12:53:58 -0400 |
|---|---|---|
| committer | jesus m. rodriguez <jesusr@redhat.com> | 2009-07-09 12:53:58 -0400 |
| commit | bc0d9c27770274f594f39d4e92a0369a6bf77afd (patch) | |
| tree | 81c05ac3caa3fd6674cfe1c601bd98ee2636fbb1 /proxy/code/src | |
| parent | 4a292bdf7af99c1fe6582eeb0a627ff69665b5de (diff) | |
| download | candlepin-bc0d9c27770274f594f39d4e92a0369a6bf77afd.tar.gz candlepin-bc0d9c27770274f594f39d4e92a0369a6bf77afd.tar.xz candlepin-bc0d9c27770274f594f39d4e92a0369a6bf77afd.zip | |
first cut at UserApi
Diffstat (limited to 'proxy/code/src')
5 files changed, 124 insertions, 2 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java new file mode 100644 index 0000000..97702bb --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java @@ -0,0 +1,42 @@ +/** + * 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.User; + +import javax.ws.rs.Consumes; +import javax.ws.rs.FormParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + + +/** + * REST api gateway for the User object. + */ +@Path("/user") +public class UserApi { + @POST + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED}) + @Produces(MediaType.APPLICATION_JSON) + public User newUser(@FormParam("login") String login, + @FormParam("password") String password) { + + System.out.println("newUser(" + login + ", " + password + ")"); + return new User(login, password); + } + +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/test/UserApiTest.java b/proxy/code/src/org/fedoraproject/candlepin/api/test/UserApiTest.java new file mode 100644 index 0000000..b53f894 --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/api/test/UserApiTest.java @@ -0,0 +1,46 @@ +/** + * 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.test; + +import org.fedoraproject.candlepin.api.UserApi; +import org.fedoraproject.candlepin.model.User; + +import junit.framework.TestCase; + + +/** + * UserApiTest + * @version $Rev$ + */ +public class UserApiTest extends TestCase { + private UserApi api = new UserApi(); + + public void testNewUser() { + User user = api.newUser("candlepin", "cp_p@$sw0rd"); + assertNotNull(user); + assertEquals("candlepin", user.getLogin()); + assertEquals("cp_p@$sw0rd", user.getPassword()); + + user = api.newUser(null, null); + assertNotNull(user); + assertNull(user.getLogin()); + assertNull(user.getPassword()); + + user = api.newUser("", ""); + assertNotNull(user); + assertEquals("", user.getLogin()); + assertEquals("", user.getPassword()); + } +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/BaseModel.java b/proxy/code/src/org/fedoraproject/candlepin/model/BaseModel.java index 43468ec..56ee5ba 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/BaseModel.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/BaseModel.java @@ -16,14 +16,20 @@ package org.fedoraproject.candlepin.model; import java.util.UUID; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + /** * @author mmccune * */ +@XmlRootElement public class BaseModel { - private String uuid; - private String name; + @XmlElement + private String uuid; + @XmlElement + private String name; /** * Construct new with UUID diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java b/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java index 8e50ef5..6beaa68 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/Organization.java @@ -17,11 +17,17 @@ package org.fedoraproject.candlepin.model; import java.util.LinkedList; import java.util.List; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement public class Organization extends BaseModel { + @XmlElement private List<Consumer> consumers; + @XmlElement private List<EntitlementPool> entitlementPools; + @XmlElement private List<User> users; /** diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/User.java b/proxy/code/src/org/fedoraproject/candlepin/model/User.java index eda58b1..a44df66 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/User.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/User.java @@ -14,14 +14,36 @@ */ package org.fedoraproject.candlepin.model; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +@XmlRootElement public class User extends BaseModel { + @XmlElement private Organization organization; + @XmlElement private String login; + @XmlElement private String password; /** + * @param login + * @param password + */ + public User(String login, String password) { + this.login = login; + this.password = password; + } + + /** + * Default ctor + */ + public User() { + this("", ""); + } + + /** * @return the login */ public String getLogin() { |
