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.admin.repository.remote.DefaultRemoteRepositoryAdmin;
26 import org.apache.archiva.metadata.repository.MetadataRepository;
27 import org.apache.archiva.metadata.repository.RepositorySession;
28 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
29 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
30 import org.apache.struts2.StrutsSpringTestCase;
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 StrutsSpringTestCase
46 private RepositoriesAction action;
48 protected void setUp()
52 action = (RepositoriesAction) getActionProxy( "/admin/index.action" ).getAction();
57 protected String[] getContextLocations()
59 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
62 public void testGetRepositories()
65 MockControl control = MockControl.createControl( MetadataRepository.class );
66 MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
67 control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
68 Arrays.asList( "20091125.123456.678" ) );
69 control.expectAndReturn(
70 metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
71 new RepositoryStatistics() );
72 control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
73 Arrays.asList( "20091112.012345.012" ) );
74 control.expectAndReturn(
75 metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID, "20091112.012345.012" ),
76 new RepositoryStatistics() );
79 RepositorySession session = mock( RepositorySession.class );
80 when( session.getRepository() ).thenReturn( metadataRepository );
81 TestRepositorySessionFactory factory =
82 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
83 factory.setRepositorySession( session );
85 ServletRunner sr = new ServletRunner();
86 ServletUnitClient sc = sr.newClient();
88 action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
91 String result = action.execute();
92 assertEquals( Action.SUCCESS, result );
94 // TODO: for some reason servletunit is not populating the port of the servlet request
95 assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
97 assertNotNull( action.getManagedRepositories() );
98 assertNotNull( action.getRemoteRepositories() );
99 assertNotNull( action.getRepositoryStatistics() );
101 assertEquals( 2, action.getManagedRepositories().size() );
102 assertEquals( 2, action.getRemoteRepositories().size() );
103 assertEquals( 2, action.getRepositoryStatistics().size() );
108 public void testSecureActionBundle()
109 throws SecureActionException
111 SecureActionBundle bundle = action.getSecureActionBundle();
112 assertTrue( bundle.requiresAuthentication() );
113 assertEquals( 1, bundle.getAuthorizationTuples().size() );