aboutsummaryrefslogtreecommitdiffstats
path: root/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test
diff options
context:
space:
mode:
authorTrevor Bramwell <tbramwell@linuxfoundation.org>2016-09-12 11:06:56 -0700
committerTrevor Bramwell <tbramwell@linuxfoundation.org>2016-09-12 11:07:49 -0700
commitcf864337c13b4638c588badf3f589f9e39318c95 (patch)
treede6f96976a0e8986abd3176026790c2e33272bc5 /upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test
parent42357cd33b44b22dbebec8cdecdb29b9d76e5f99 (diff)
Move ODL-AAA-MOON under 'upstream' Directory
Change-Id: Ie010fbe3899e151421940908dbe8675aade54e2d Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
Diffstat (limited to 'upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test')
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/persistence/PasswordHashTest.java93
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/DomainHandlerTest.java130
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/HandlerTest.java38
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/IDMTestStore.java271
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/RoleHandlerTest.java95
-rw-r--r--upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/UserHandlerTest.java96
6 files changed, 723 insertions, 0 deletions
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/persistence/PasswordHashTest.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/persistence/PasswordHashTest.java
new file mode 100644
index 00000000..44fadf7a
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/persistence/PasswordHashTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.persistence;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.aaa.api.IDMStoreException;
+import org.opendaylight.aaa.api.IIDMStore;
+import org.opendaylight.aaa.api.PasswordCredentials;
+import org.opendaylight.aaa.api.SHA256Calculator;
+import org.opendaylight.aaa.api.model.Domain;
+import org.opendaylight.aaa.api.model.Grant;
+import org.opendaylight.aaa.api.model.Grants;
+import org.opendaylight.aaa.api.model.Role;
+import org.opendaylight.aaa.api.model.User;
+import org.opendaylight.aaa.api.model.Users;
+import org.opendaylight.aaa.idm.IdmLightProxy;
+import org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLightModule;
+
+/*
+ * @Author - Sharon Aicler (saichler@cisco.com)
+*/
+public class PasswordHashTest {
+
+ @Before
+ public void before() throws IDMStoreException{
+ IIDMStore store = Mockito.mock(IIDMStore.class);
+ AAAIDMLightModule.setStore(store);
+ Domain domain = new Domain();
+ domain.setName("sdn");
+ domain.setDomainid("sdn");
+
+ Mockito.when(store.readDomain("sdn")).thenReturn(domain);
+ Creds c = new Creds();
+ Users users = new Users();
+ User user = new User();
+ user.setName("admin");
+ user.setUserid(c.username());
+ user.setDomainid("sdn");
+ user.setSalt("ABCD");
+ user.setPassword(SHA256Calculator.getSHA256(c.password(),user.getSalt()));
+ List<User> lu = new LinkedList<>();
+ lu.add(user);
+ users.setUsers(lu);
+
+ Grants grants = new Grants();
+ Grant grant = new Grant();
+ List<Grant> g = new ArrayList<>();
+ g.add(grant);
+ grant.setDomainid("sdn");
+ grant.setRoleid("admin");
+ grant.setUserid("admin");
+ grants.setGrants(g);
+ Role role = new Role();
+ role.setRoleid("admin");
+ role.setName("admin");
+ Mockito.when(store.readRole("admin")).thenReturn(role);
+ Mockito.when(store.getUsers(c.username(), c.domain())).thenReturn(users);
+ Mockito.when(store.getGrants(c.domain(), c.username())).thenReturn(grants);
+ }
+
+ @Test
+ public void testPasswordHash(){
+ IdmLightProxy proxy = new IdmLightProxy();
+ proxy.authenticate(new Creds());
+ }
+
+ private static class Creds implements PasswordCredentials {
+ @Override
+ public String username() {
+ return "admin";
+ }
+ @Override
+ public String password() {
+ return "admin";
+ }
+ @Override
+ public String domain() {
+ return "sdn";
+ }
+ }
+}
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/DomainHandlerTest.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/DomainHandlerTest.java
new file mode 100644
index 00000000..a8b964ae
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/DomainHandlerTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.rest.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.MediaType;
+import org.junit.Test;
+import org.opendaylight.aaa.api.model.Domain;
+import org.opendaylight.aaa.api.model.Domains;
+import org.opendaylight.aaa.api.model.IDMError;
+import org.opendaylight.aaa.api.model.Roles;
+
+public class DomainHandlerTest extends HandlerTest{
+
+ @Test
+ public void testDomainHandler() {
+ //check default domains
+ Domains domains = resource().path("/v1/domains").get(Domains.class);
+ assertNotNull(domains);
+ assertEquals(1, domains.getDomains().size());
+ assertTrue(domains.getDomains().get(0).getName().equals("sdn"));
+
+ //check existing domain
+ Domain domain = resource().path("/v1/domains/0").get(Domain.class);
+ assertNotNull(domain);
+ assertTrue(domain.getName().equals("sdn"));
+
+ //check not exist domain
+ try {
+ resource().path("/v1/domains/5").get(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Not found! domain id"));
+ }
+
+ // check create domain
+ Map<String, String> domainData = new HashMap<String, String>();
+ domainData.put("name","dom1");
+ domainData.put("description","test dom");
+ domainData.put("domainid","1");
+ domainData.put("enabled","true");
+ ClientResponse clientResponse = resource().path("/v1/domains").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, domainData);
+ assertEquals(201, clientResponse.getStatus());
+
+ // check update domain data
+ domainData.put("name","dom1Update");
+ clientResponse = resource().path("/v1/domains/1").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, domainData);
+ assertEquals(200, clientResponse.getStatus());
+ domain = resource().path("/v1/domains/1").get(Domain.class);
+ assertNotNull(domain);
+ assertTrue(domain.getName().equals("dom1Update"));
+
+ // check create grant
+ Map<String, String> grantData = new HashMap<String, String>();
+ grantData.put("roleid","1");
+ clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+ assertEquals(201, clientResponse.getStatus());
+
+ // check create existing grant
+ clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+ assertEquals(403, clientResponse.getStatus());
+
+ // check create grant with invalid domain id
+ clientResponse = resource().path("/v1/domains/5/users/0/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, grantData);
+ assertEquals(404, clientResponse.getStatus());
+
+ // check validate user (admin)
+ Map<String, String> usrPwdData = new HashMap<String, String>();
+ usrPwdData.put("username","admin");
+ usrPwdData.put("userpwd","admin");
+ clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
+ assertEquals(200, clientResponse.getStatus());
+
+ // check validate user (admin) with wrong password
+ usrPwdData.put("userpwd","1234");
+ clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrPwdData);
+ assertEquals(401, clientResponse.getStatus());
+
+ // check get user (admin) roles
+ Roles usrRoles = resource().path("/v1/domains/0/users/0/roles").get(Roles.class);
+ assertNotNull(usrRoles);
+ assertTrue(usrRoles.getRoles().size() > 1);
+
+ // check get invalid user roles
+ try {
+ resource().path("/v1/domains/0/users/5/roles").get(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ }
+
+ // check delete grant
+ clientResponse = resource().path("/v1/domains/0/users/0/roles/0").delete(ClientResponse.class);
+ assertEquals(204, clientResponse.getStatus());
+
+ // check delete grant for invalid domain
+ clientResponse = resource().path("/v1/domains/3/users/0/roles/0").delete(ClientResponse.class);
+ assertEquals(404, clientResponse.getStatus());
+
+ // check delete domain
+ clientResponse = resource().path("/v1/domains/1").delete(ClientResponse.class);
+ assertEquals(204, clientResponse.getStatus());
+
+ // check delete not existing domain
+ try {
+ resource().path("/v1/domains/1").delete(IDMError.class);
+ fail("Shoulda failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Not found! Domain id"));
+ }
+ }
+}
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/HandlerTest.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/HandlerTest.java
new file mode 100644
index 00000000..7b8eebb4
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/HandlerTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.rest.test;
+
+import com.sun.jersey.spi.container.servlet.WebComponent;
+import com.sun.jersey.test.framework.AppDescriptor;
+import com.sun.jersey.test.framework.JerseyTest;
+import com.sun.jersey.test.framework.WebAppDescriptor;
+import org.junit.Before;
+import org.opendaylight.aaa.idm.IdmLightApplication;
+import org.opendaylight.aaa.idm.StoreBuilder;
+import org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLightModule;
+
+
+public abstract class HandlerTest extends JerseyTest {
+
+ protected IDMTestStore testStore = new IDMTestStore();
+
+ @Override
+ protected AppDescriptor configure() {
+ return new WebAppDescriptor.Builder()
+ .initParam(WebComponent.RESOURCE_CONFIG_CLASS, IdmLightApplication.class.getName())
+ .build();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ StoreBuilder.init(testStore);
+ AAAIDMLightModule.setStore(testStore);
+ }
+}
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/IDMTestStore.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/IDMTestStore.java
new file mode 100644
index 00000000..0fed2789
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/IDMTestStore.java
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.rest.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.aaa.api.IDMStoreException;
+import org.opendaylight.aaa.api.IIDMStore;
+import org.opendaylight.aaa.api.model.Domain;
+import org.opendaylight.aaa.api.model.Domains;
+import org.opendaylight.aaa.api.model.Grant;
+import org.opendaylight.aaa.api.model.Grants;
+import org.opendaylight.aaa.api.model.Role;
+import org.opendaylight.aaa.api.model.Roles;
+import org.opendaylight.aaa.api.model.User;
+import org.opendaylight.aaa.api.model.Users;
+
+public class IDMTestStore implements IIDMStore {
+
+ private List<Domain> domains = new ArrayList<Domain>();
+ private List<Grant> grants = new ArrayList<Grant>();
+ private List<Role> roles = new ArrayList<Role>();
+ private List<User> users = new ArrayList<User>();
+
+ public IDMTestStore() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public Domain writeDomain(Domain domain) throws IDMStoreException {
+ domain.setDomainid(String.valueOf(domains.size()));
+ domains.add(domain);
+ return domain;
+ }
+
+ @Override
+ public Domain readDomain(String domainid) throws IDMStoreException {
+ for(Domain dom : domains) {
+ if (dom.getDomainid().equals(domainid)) {
+ return dom;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Domain deleteDomain(String domainid) throws IDMStoreException {
+ for(Domain dom : domains) {
+ if (dom.getDomainid().equals(domainid)) {
+ domains.remove(dom);
+ return dom;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Domain updateDomain(Domain domain) throws IDMStoreException {
+ for(Domain dom : domains) {
+ if (dom.getDomainid().equals(domain.getDomainid())) {
+ domains.remove(dom);
+ domains.add(domain);
+ return domain;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Domains getDomains() throws IDMStoreException {
+ Domains doms = new Domains();
+ doms.setDomains(domains);
+ return doms;
+ }
+
+ @Override
+ public Role writeRole(Role role) throws IDMStoreException {
+ role.setRoleid(String.valueOf(roles.size()));
+ roles.add(role);
+ return role;
+ }
+
+ @Override
+ public Role readRole(String roleid) throws IDMStoreException {
+ for (Role role : roles) {
+ if (role.getRoleid().equals(roleid)) {
+ return role;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Role deleteRole(String roleid) throws IDMStoreException {
+ for (Role role : roles) {
+ if (role.getRoleid().equals(roleid)) {
+ roles.remove(role);
+ return role;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Role updateRole(Role role) throws IDMStoreException {
+ for (Role inRole : roles) {
+ if (inRole.getRoleid().equals(role.getRoleid())) {
+ roles.remove(inRole);
+ roles.add(role);
+ return role;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Roles getRoles() throws IDMStoreException {
+ Roles rols = new Roles();
+ rols.setRoles(roles);
+ return rols;
+ }
+
+ @Override
+ public User writeUser(User user) throws IDMStoreException {
+ user.setUserid(String.valueOf(users.size()));
+ users.add(user);
+ return user;
+ }
+
+ @Override
+ public User readUser(String userid) throws IDMStoreException {
+ for(User usr : users) {
+ if (usr.getUserid().equals(userid)) {
+ return usr;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public User deleteUser(String userid) throws IDMStoreException {
+ for(User usr : users) {
+ if (usr.getUserid().equals(userid)) {
+ users.remove(usr);
+ return usr;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public User updateUser(User user) throws IDMStoreException {
+ for(User usr : users) {
+ if (usr.getUserid().equals(user.getUserid())) {
+ users.remove(usr);
+ users.add(user);
+ return usr;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Users getUsers() throws IDMStoreException {
+ Users usrs = new Users();
+ usrs.setUsers(users);
+ return usrs;
+ }
+
+ @Override
+ public Users getUsers(String username, String domainId) throws IDMStoreException {
+ Users usrs = new Users();
+ User user = null;
+ Domain domain = null;
+ for(User usr : users) {
+ if (usr.getName().equals(username)) {
+ user = usr;
+ break;
+ }
+ }
+ for(Domain dom : domains) {
+ if (dom.getDomainid().equals(domainId)) {
+ domain = dom;
+ break;
+ }
+ }
+ if (user == null || domain == null)
+ return usrs;
+ for (Grant grant : grants) {
+ if (grant.getUserid().equals(user.getUserid()) && grant.getDomainid().equals(domain.getDomainid())) {
+ List<User> usrList = new ArrayList<User>();
+ usrList.add(user);
+ usrs.setUsers(usrList);
+ break;
+ }
+ }
+ return usrs;
+ }
+
+ @Override
+ public Grant writeGrant(Grant grant) throws IDMStoreException {
+ grant.setGrantid(String.valueOf(grants.size()));
+ grants.add(grant);
+ return grant;
+ }
+
+ @Override
+ public Grant readGrant(String grantid) throws IDMStoreException {
+ for (Grant grant : grants) {
+ if (grant.getGrantid().equals(grantid)) {
+ return grant;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Grant deleteGrant(String grantid) throws IDMStoreException {
+ for (Grant grant : grants) {
+ if (grant.getGrantid().equals(grantid)) {
+ grants.remove(grant);
+ return grant;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Grants getGrants(String domainid, String userid) throws IDMStoreException {
+ Grants usrGrants = new Grants();
+ List<Grant> usrGrant = new ArrayList<Grant>();
+ for (Grant grant : grants) {
+ if (grant.getUserid().equals(userid) && grant.getDomainid().equals(domainid)) {
+ usrGrant.add(grant);
+ }
+ }
+ usrGrants.setGrants(usrGrant);
+ return usrGrants;
+ }
+
+ @Override
+ public Grants getGrants(String userid) throws IDMStoreException {
+ Grants usrGrants = new Grants();
+ List<Grant> usrGrant = new ArrayList<Grant>();
+ for (Grant grant : grants) {
+ if (grant.getUserid().equals(userid)) {
+ usrGrant.add(grant);
+ }
+ }
+ usrGrants.setGrants(usrGrant);
+ return usrGrants;
+ }
+
+ @Override
+ public Grant readGrant(String domainid, String userid, String roleid) throws IDMStoreException {
+ for (Grant grant : grants) {
+ if (grant.getDomainid().equals(domainid) && grant.getUserid().equals(userid) && grant.getRoleid().equals(roleid)) {
+ return grant;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/RoleHandlerTest.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/RoleHandlerTest.java
new file mode 100644
index 00000000..baf59558
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/RoleHandlerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.rest.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.MediaType;
+import org.junit.Test;
+import org.opendaylight.aaa.api.model.IDMError;
+import org.opendaylight.aaa.api.model.Role;
+import org.opendaylight.aaa.api.model.Roles;
+
+
+public class RoleHandlerTest extends HandlerTest{
+
+ @Test
+ public void testRoleHandler() {
+ //check default roles
+ Roles roles = resource().path("/v1/roles").get(Roles.class);
+ assertNotNull(roles);
+ List<Role> roleList = roles.getRoles();
+ assertEquals(2, roleList.size());
+ for (Role role : roleList) {
+ assertTrue(role.getName().equals("admin") || role.getName().equals("user"));
+ }
+
+ //check existing role
+ Role role = resource().path("/v1/roles/0").get(Role.class);
+ assertNotNull(role);
+ assertTrue(role.getName().equals("admin"));
+
+ //check not exist Role
+ try {
+ resource().path("/v1/roles/5").get(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("role not found"));
+ }
+
+ // check create Role
+ Map<String, String> roleData = new HashMap<String, String>();
+ roleData.put("name","role1");
+ roleData.put("description","test Role");
+ roleData.put("domainid","0");
+ ClientResponse clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, roleData);
+ assertEquals(201, clientResponse.getStatus());
+
+ // check create Role missing name data
+ roleData.remove("name");
+ try {
+ clientResponse = resource().path("/v1/roles").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, roleData);
+ assertEquals(404, clientResponse.getStatus());
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(500, resp.getStatus());
+ }
+
+ // check update Role data
+ roleData.put("name","role1Update");
+ clientResponse = resource().path("/v1/roles/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, roleData);
+ assertEquals(200, clientResponse.getStatus());
+ role = resource().path("/v1/roles/2").get(Role.class);
+ assertNotNull(role);
+ assertTrue(role.getName().equals("role1Update"));
+
+ // check delete Role
+ clientResponse = resource().path("/v1/roles/2").delete(ClientResponse.class);
+ assertEquals(204, clientResponse.getStatus());
+
+ // check delete not existing Role
+ try {
+ resource().path("/v1/roles/2").delete(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("role id not found"));
+ }
+ }
+}
diff --git a/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/UserHandlerTest.java b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/UserHandlerTest.java
new file mode 100644
index 00000000..115546b6
--- /dev/null
+++ b/upstream/odl-aaa-moon/aaa/aaa-idmlight/src/test/java/org/opendaylight/aaa/idm/rest/test/UserHandlerTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.aaa.idm.rest.test;
+
+import static org.junit.Assert.*;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.MediaType;
+import org.junit.Test;
+import org.opendaylight.aaa.api.model.IDMError;
+import org.opendaylight.aaa.api.model.User;
+import org.opendaylight.aaa.api.model.Users;
+
+public class UserHandlerTest extends HandlerTest {
+
+ @Test
+ public void testUserHandler() {
+ //check default users
+ Users users = resource().path("/v1/users").get(Users.class);
+ assertNotNull(users);
+ List<User> usrList = users.getUsers();
+ assertEquals(2, usrList.size());
+ for (User usr : usrList) {
+ assertTrue(usr.getName().equals("admin") || usr.getName().equals("user"));
+ }
+
+ //check existing user
+ User usr = resource().path("/v1/users/0").get(User.class);
+ assertNotNull(usr);
+ assertTrue(usr.getName().equals("admin"));
+
+ //check not exist user
+ try {
+ resource().path("/v1/users/5").get(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("user not found"));
+ }
+
+ // check create user
+ Map<String, String> usrData = new HashMap<String, String>();
+ usrData.put("name","usr1");
+ usrData.put("description","test user");
+ usrData.put("enabled","true");
+ usrData.put("email","user1@usr.org");
+ usrData.put("password","ChangeZbadPa$$w0rd");
+ usrData.put("domainid","0");
+ ClientResponse clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrData);
+ assertEquals(201, clientResponse.getStatus());
+
+ // check create user missing name data
+ usrData.remove("name");
+ try {
+ clientResponse = resource().path("/v1/users").type(MediaType.APPLICATION_JSON).post(ClientResponse.class, usrData);
+ assertEquals(400, clientResponse.getStatus());
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(500, resp.getStatus());
+ }
+
+ // check update user data
+ usrData.put("name","usr1Update");
+ clientResponse = resource().path("/v1/users/2").type(MediaType.APPLICATION_JSON).put(ClientResponse.class, usrData);
+ assertEquals(200, clientResponse.getStatus());
+ usr = resource().path("/v1/users/2").get(User.class);
+ assertNotNull(usr);
+ assertTrue(usr.getName().equals("usr1Update"));
+
+ // check delete user
+ clientResponse = resource().path("/v1/users/2").delete(ClientResponse.class);
+ assertEquals(204, clientResponse.getStatus());
+
+ // check delete not existing user
+ try {
+ resource().path("/v1/users/2").delete(IDMError.class);
+ fail("Should failed with 404!");
+ } catch (UniformInterfaceException e) {
+ ClientResponse resp = e.getResponse();
+ assertEquals(404, resp.getStatus());
+ assertTrue(resp.getEntity(IDMError.class).getMessage().contains("Couldn't find user"));
+ }
+ }
+
+}