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 com.meterware.servletunit.ServletRunner;
23 import com.meterware.servletunit.ServletUnitClient;
24 import com.opensymphony.xwork2.Action;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.metadata.repository.RepositorySession;
27 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
28 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
29 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
32 import org.codehaus.redback.integration.interceptor.SecureActionException;
33 import org.easymock.MockControl;
35 import java.util.Arrays;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.when;
41 * Test the repositories action returns the correct data.
43 public class RepositoriesActionTest
44 extends PlexusInSpringTestCase
46 private RepositoriesAction action;
48 protected void setUp()
55 action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
59 // clean up cache - TODO: move handling to plexus-spring
60 applicationContext.close();
65 public void testGetRepositories()
68 MockControl control = MockControl.createControl( MetadataRepository.class );
69 MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
70 control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
71 Arrays.asList( "20091125.123456.678" ) );
72 control.expectAndReturn( metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID,
73 "20091125.123456.678" ),
74 new RepositoryStatistics() );
75 control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
76 Arrays.asList( "20091112.012345.012" ) );
77 control.expectAndReturn( metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID,
78 "20091112.012345.012" ),
79 new RepositoryStatistics() );
82 RepositorySession session = mock( RepositorySession.class );
83 when( session.getRepository() ).thenReturn( metadataRepository );
84 TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
85 factory.setRepositorySession( session );
87 ServletRunner sr = new ServletRunner();
88 ServletUnitClient sc = sr.newClient();
90 action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
92 String result = action.execute();
93 assertEquals( Action.SUCCESS, result );
95 // TODO: for some reason servletunit is not populating the port of the servlet request
96 assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
98 assertNotNull( action.getManagedRepositories() );
99 assertNotNull( action.getRemoteRepositories() );
100 assertNotNull( action.getRepositoryStatistics() );
102 assertEquals( 2, action.getManagedRepositories().size() );
103 assertEquals( 2, action.getRemoteRepositories().size() );
104 assertEquals( 2, action.getRepositoryStatistics().size() );
109 public void testSecureActionBundle()
110 throws SecureActionException
112 SecureActionBundle bundle = action.getSecureActionBundle();
113 assertTrue( bundle.requiresAuthentication() );
114 assertEquals( 1, bundle.getAuthorizationTuples().size() );