Merge "BUG-2329 Add test for anyxmls inside rpc resonse for netcfon-connector"
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / authorization / AuthorizationTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.authorization;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Map.Entry;
16
17 import org.junit.Assert;
18 import org.junit.Test;
19
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.utils.NodeCreator;
22
23         public class AuthorizationTest {
24
25         @Test
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>();
31
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);
36                 }
37
38                 resourceMap.put(resourceGroup, resourceList);
39
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));
48                         }
49                 }
50         }
51
52         @Test
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"));
58         }
59
60         @Test
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"));
66         }
67
68         @Test
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);
76         }
77 }