1 package org.apache.maven.archiva.security;
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 java.util.List;
24 import org.apache.commons.lang.StringUtils;
25 import org.junit.Test;
28 * DefaultUserRepositoriesTest
32 public class DefaultUserRepositoriesTest
33 extends AbstractSecurityTest
35 protected String getPlexusConfigLocation()
37 return "org/apache/maven/archiva/security/DefaultUserRepositoriesTest.xml";
41 public void testGetObservableRepositoryIds()
45 createUser( USER_ALPACA, "Al 'Archiva' Paca" );
47 assertEquals( "Expected users", 3, securitySystem.getUserManager().getUsers().size() );
49 // some unassigned repo observer roles.
50 setupRepository( "central" );
51 setupRepository( "corporate" );
52 setupRepository( "internal" );
53 setupRepository( "snapshots" );
54 setupRepository( "secret" );
56 // some assigned repo observer roles.
57 assignRepositoryObserverRole( USER_ALPACA, "corporate" );
58 assignRepositoryObserverRole( USER_ALPACA, "central" );
59 assignRepositoryObserverRole( USER_GUEST, "corporate" );
60 // the global repo observer role.
61 assignGlobalRepositoryObserverRole( USER_ADMIN );
63 assertRepoIds( new String[] { "central", "corporate" }, userRepos.getObservableRepositoryIds( USER_ALPACA ) );
64 assertRepoIds( new String[] { "coporate" }, userRepos.getObservableRepositoryIds( USER_GUEST ) );
65 assertRepoIds( new String[] { "central", "internal", "corporate", "snapshots", "secret" }, userRepos
66 .getObservableRepositoryIds( USER_ADMIN ) );
69 private void assertRepoIds( String[] expectedRepoIds, List<String> observableRepositoryIds )
71 assertNotNull( "Observable Repository Ids cannot be null.", observableRepositoryIds );
73 if ( expectedRepoIds.length != observableRepositoryIds.size() )
75 fail( "Size of Observable Repository Ids wrong, expected <" + expectedRepoIds.length + "> but got <"
76 + observableRepositoryIds.size() + "> instead. \nExpected: [" + StringUtils.join( expectedRepoIds, "," )
77 + "]\nActual: [" + StringUtils.join( observableRepositoryIds.iterator(), "," ) + "]" );
81 private void assignGlobalRepositoryObserverRole( String principal )
84 roleManager.assignRole( ArchivaRoleConstants.TEMPLATE_GLOBAL_REPOSITORY_OBSERVER, principal );