View Javadoc

1   package org.apache.maven.continuum.web.action;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.web.action.AbstractActionTest;
23  import org.apache.maven.continuum.Continuum;
24  import org.apache.maven.continuum.model.project.ProjectGroup;
25  import org.apache.maven.continuum.web.action.stub.ProjectGroupActionStub;
26  import org.apache.maven.continuum.web.bean.ProjectGroupUserBean;
27  import org.codehaus.plexus.redback.rbac.RBACManager;
28  import org.codehaus.plexus.redback.rbac.Role;
29  import org.codehaus.plexus.redback.rbac.UserAssignment;
30  import org.codehaus.plexus.redback.rbac.jdo.JdoRole;
31  import org.codehaus.plexus.redback.rbac.jdo.JdoUserAssignment;
32  import org.jmock.Mock;
33  
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  public class ProjectGroupActionTest
38      extends AbstractActionTest
39  {
40      private ProjectGroupActionStub action;
41  
42      private Mock continuum;
43  
44      private Mock rbac;
45  
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51          action = new ProjectGroupActionStub();
52          continuum = mock( Continuum.class );
53          rbac = mock( RBACManager.class );
54  
55          action.setContinuum( (Continuum) continuum.proxy() );
56          action.setRbacManager( (RBACManager) rbac.proxy() );
57      }
58  
59      public void testViewMembersWithProjectAdminRole()
60          throws Exception
61      {
62          ProjectGroup group = new ProjectGroup();
63          group.setName( "Project A" );
64  
65          List<Role> roles = new ArrayList<Role>();
66          Role role1 = new JdoRole();
67          role1.setName( "Project User - Project A" );
68          roles.add( role1 );
69  
70          Role role2 = new JdoRole();
71          role2.setName( "Continuum Manage Scheduling" );
72          roles.add( role2 );
73  
74          Role role3 = new JdoRole();
75          role3.setName( "Project Developer - Project A" );
76          roles.add( role3 );
77  
78          Role role4 = new JdoRole();
79          role4.setName( "Project Administrator - Project A" );
80          roles.add( role4 );
81  
82          List<UserAssignment> userAssignments = new ArrayList<UserAssignment>();
83          UserAssignment ua1 = new JdoUserAssignment();
84          ua1.setPrincipal( "user1" );
85          userAssignments.add( ua1 );
86  
87          List<Role> eRoles = roles;
88  
89          continuum.expects( once() ).method( "getProjectGroupWithProjects" ).will( returnValue( group ) );
90          rbac.expects( once() ).method( "getAllRoles" ).will( returnValue( roles ) );
91          rbac.expects( once() ).method( "getUserAssignmentsForRoles" ).will( returnValue( userAssignments ) );
92          rbac.expects( once() ).method( "getEffectivelyAssignedRoles" ).will( returnValue( eRoles ) );
93  
94          action.members();
95  
96          continuum.verify();
97          rbac.verify();
98  
99          List<ProjectGroupUserBean> users = action.getProjectGroupUsers();
100         assertEquals( 1, users.size() );
101         assertTrue( users.get( 0 ).isAdministrator() );
102         assertTrue( users.get( 0 ).isDeveloper() );
103         assertTrue( users.get( 0 ).isUser() );
104     }
105 
106     public void testViewMembersWithProjectUserRole()
107         throws Exception
108     {
109         ProjectGroup group = new ProjectGroup();
110         group.setName( "Project A" );
111 
112         List<Role> roles = new ArrayList<Role>();
113         Role role1 = new JdoRole();
114         role1.setName( "Project User - Project A" );
115         roles.add( role1 );
116 
117         Role role2 = new JdoRole();
118         role2.setName( "Continuum Manage Scheduling" );
119         roles.add( role2 );
120 
121         Role role3 = new JdoRole();
122         role3.setName( "Project Developer - test-group" );
123         roles.add( role3 );
124 
125         Role role4 = new JdoRole();
126         role4.setName( "Project Administrator - test-group" );
127         roles.add( role4 );
128 
129         Role role5 = new JdoRole();
130         role5.setName( "Project Administrator - Project C" );
131         roles.add( role5 );
132 
133         List<UserAssignment> userAssignments = new ArrayList<UserAssignment>();
134         UserAssignment ua1 = new JdoUserAssignment();
135         ua1.setPrincipal( "user1" );
136         userAssignments.add( ua1 );
137 
138         List<Role> eRoles = new ArrayList<Role>();
139         eRoles.add( role1 );
140         eRoles.add( role2 );
141         eRoles.add( role5 );
142 
143         continuum.expects( once() ).method( "getProjectGroupWithProjects" ).will( returnValue( group ) );
144         rbac.expects( once() ).method( "getAllRoles" ).will( returnValue( roles ) );
145         rbac.expects( once() ).method( "getUserAssignmentsForRoles" ).will( returnValue( userAssignments ) );
146         rbac.expects( once() ).method( "getEffectivelyAssignedRoles" ).will( returnValue( eRoles ) );
147 
148         action.members();
149 
150         continuum.verify();
151         rbac.verify();
152 
153         List<ProjectGroupUserBean> users = action.getProjectGroupUsers();
154         assertEquals( 1, users.size() );
155         assertFalse( users.get( 0 ).isAdministrator() );
156         assertFalse( users.get( 0 ).isDeveloper() );
157         assertTrue( users.get( 0 ).isUser() );
158     }
159 }