1 package org.apache.archiva.redback.role.template;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import junit.framework.TestCase;
23 import org.apache.archiva.redback.rbac.Permission;
24 import org.apache.archiva.redback.rbac.RBACManager;
25 import org.apache.archiva.redback.rbac.Role;
26 import org.apache.archiva.redback.role.template.RoleTemplateProcessor;
27 import org.codehaus.plexus.redback.role.model.ModelTemplate;
28 import org.codehaus.plexus.redback.role.model.RedbackRoleModel;
29 import org.codehaus.plexus.redback.role.model.io.stax.RedbackRoleModelStaxReader;
30 import org.apache.archiva.redback.role.processor.RoleModelProcessor;
31 import org.apache.archiva.redback.role.util.RoleModelUtils;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
37 import javax.inject.Inject;
38 import javax.inject.Named;
44 * @author: Jesse McConnell <jesse@codehaus.org>
47 @RunWith( SpringJUnit4ClassRunner.class )
48 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
49 public class RoleTemplateProcessorTest
54 @Named( value = "rBACManager#memory" )
55 private RBACManager rbacManager;
57 @Inject @Named(value = "modelProcessor#memory")
58 private RoleModelProcessor roleProcessor;
60 @Inject @Named(value = "templateProcessor#memory")
61 private RoleTemplateProcessor templateProcessor;
64 * Creates a new RbacStore which contains no data.
66 protected void setUp()
74 return System.getProperty( "basedir" );
78 public void testLoading()
81 File resource = new File( getBasedir() + "/src/test/template-tests/redback-1.xml" );
83 assertNotNull( resource );
85 RedbackRoleModelStaxReader modelReader = new RedbackRoleModelStaxReader();
87 RedbackRoleModel redback = modelReader.read( resource.getAbsolutePath() );
89 assertNotNull( redback );
91 roleProcessor.process( redback );
93 templateProcessor.create( redback, "test-template", "foo" );
95 ModelTemplate template = RoleModelUtils.getModelTemplate( redback, "test-template" );
97 String templateName = template.getNamePrefix() + template.getDelimiter() + "foo";
99 assertTrue( rbacManager.resourceExists( "cornflakes name" ) );
101 assertTrue( rbacManager.roleExists( templateName ) );
103 Role testRole = rbacManager.getRole( templateName );
105 assertNotNull( testRole );
107 Permission testPermission = (Permission) testRole.getPermissions().get( 0 );
109 assertNotNull( testPermission );
111 assertEquals( "Eat Cornflakes - cornflakes name", testPermission.getName() );
113 templateProcessor.remove( redback, "test-template", "foo" );
115 assertFalse( rbacManager.roleExists( templateName ) );
117 templateProcessor.create( redback, "test-template-2", "foo" );
119 ModelTemplate template2 = RoleModelUtils.getModelTemplate( redback, "test-template-2" );
121 String templateName2 = template2.getNamePrefix() + template2.getDelimiter() + "foo";
123 assertTrue( rbacManager.roleExists( templateName2 ) );
125 Role role = rbacManager.getRole( templateName2 );
127 assertNotNull( role );
129 assertEquals( 3, template2.getPermissions().size() );
130 assertEquals( 3, role.getPermissions().size() );
132 assertEquals( 1, role.getChildRoleNames().size() );