1 package org.apache.maven.archiva.web.action.admin.repositories;
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.Arrays;
24 import com.meterware.servletunit.ServletRunner;
25 import com.meterware.servletunit.ServletUnitClient;
26 import com.opensymphony.xwork2.Action;
27 import org.apache.archiva.metadata.repository.MetadataRepository;
28 import org.apache.archiva.metadata.repository.stats.DefaultRepositoryStatisticsManager;
29 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
30 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
31 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
32 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
33 import org.codehaus.redback.integration.interceptor.SecureActionException;
34 import org.easymock.MockControl;
37 * Test the repositories action returns the correct data.
39 public class RepositoriesActionTest
40 extends PlexusInSpringTestCase
42 private RepositoriesAction action;
44 protected void setUp()
49 action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
52 public void testGetRepositories()
55 MockControl control = MockControl.createControl( MetadataRepository.class );
56 MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
57 control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
58 Arrays.asList( "20091125.123456.678" ) );
59 control.expectAndReturn(
60 metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
61 new RepositoryStatistics() );
62 control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
63 Arrays.asList( "20091112.012345.012" ) );
64 control.expectAndReturn(
65 metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID, "20091112.012345.012" ),
66 new RepositoryStatistics() );
69 DefaultRepositoryStatisticsManager statsManager =
70 (DefaultRepositoryStatisticsManager) lookup( RepositoryStatisticsManager.class );
71 statsManager.setMetadataRepository( metadataRepository );
73 ServletRunner sr = new ServletRunner();
74 ServletUnitClient sc = sr.newClient();
76 action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
78 String result = action.execute();
79 assertEquals( Action.SUCCESS, result );
81 // TODO: for some reason servletunit is not populating the port of the servlet request
82 assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
84 assertNotNull( action.getManagedRepositories() );
85 assertNotNull( action.getRemoteRepositories() );
86 assertNotNull( action.getRepositoryStatistics() );
88 assertEquals( 2, action.getManagedRepositories().size() );
89 assertEquals( 2, action.getRemoteRepositories().size() );
90 assertEquals( 2, action.getRepositoryStatistics().size() );
95 public void testSecureActionBundle()
96 throws SecureActionException
98 SecureActionBundle bundle = action.getSecureActionBundle();
99 assertTrue( bundle.requiresAuthentication() );
100 assertEquals( 1, bundle.getAuthorizationTuples().size() );