3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.authorization;
12 import java.util.ArrayList;
13 import java.util.HashMap;
15 import java.util.Map.Entry;
17 import org.junit.Assert;
18 import org.junit.Test;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.utils.NodeCreator;
23 public class AuthorizationTest {
26 public void testResources () {
27 Privilege p = Privilege.WRITE;
28 ResourceGroup resourceGroup = new ResourceGroup("NodeGroup", p);
29 Map<ResourceGroup, ArrayList<Resource>> resourceMap = new HashMap<ResourceGroup, ArrayList<Resource>>();
30 ArrayList<Resource> resourceList = new ArrayList<Resource>();
32 for (int i = 0; i < 5; i++) {
33 Node node = NodeCreator.createOFNode((long)i);
34 Resource resource = new Resource (node, p);
35 resourceList.add(resource);
38 resourceMap.put(resourceGroup, resourceList);
40 ArrayList<Resource> retrievedResourceList = resourceMap.get(resourceGroup);
41 for (Entry<ResourceGroup, ArrayList<Resource>> entry : resourceMap.entrySet()) {
42 ResourceGroup rGroup = entry.getKey();
43 Assert.assertTrue(rGroup.getGroupName().equals(resourceGroup.getGroupName()));
44 for (int i = 0; i < 5; i++) {
45 Resource resource = retrievedResourceList.get(i);
46 Assert.assertTrue(resource.getPrivilege().equals(Privilege.WRITE));
47 Assert.assertTrue(((Long)((Node)resource.getResource()).getID()).equals((long)i));
53 public void testAppRoleLevel() {
54 AppRoleLevel appRoleLevel = AppRoleLevel.APPOPERATOR;
55 Assert.assertTrue(appRoleLevel.toString().equals("App-Operator"));
56 Assert.assertTrue(appRoleLevel.toNumber() == 2);
57 Assert.assertTrue(appRoleLevel.toStringPretty().equals("Application Operator"));
61 public void testUserLevel() {
62 UserLevel userLevel = UserLevel.SYSTEMADMIN;
63 Assert.assertTrue(userLevel.toString().equals("System-Admin"));
64 Assert.assertTrue(userLevel.toNumber() == 0);
65 Assert.assertTrue(userLevel.toStringPretty().equals("System Administrator"));
69 public void testAppRoleLevelFromString() {
70 Assert.assertTrue(AppRoleLevel.fromString("App-Admin") == AppRoleLevel.APPADMIN);
71 Assert.assertTrue(AppRoleLevel.fromString("App-User") == AppRoleLevel.APPUSER);
72 Assert.assertTrue(AppRoleLevel.fromString("App-Operator") == AppRoleLevel.APPOPERATOR);
73 Assert.assertTrue(AppRoleLevel.fromString(" ") == null);
74 Assert.assertTrue(AppRoleLevel.fromString("") == null);
75 Assert.assertTrue(AppRoleLevel.fromString("App-Admini") == null);