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.memory.TestRepositorySessionFactory;
28 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
29 import org.apache.struts2.StrutsSpringTestCase;
30 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
31 import org.codehaus.redback.integration.interceptor.SecureActionException;
32 import org.easymock.MockControl;
34 import java.util.Arrays;
36 import static org.mockito.Mockito.mock;
37 import static org.mockito.Mockito.when;
40 * Test the repositories action returns the correct data.
42 public class RepositoriesActionTest
43 extends StrutsSpringTestCase
45 private RepositoriesAction action;
47 protected void setUp()
52 //action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
53 action = (RepositoriesAction) getActionProxy( "/admin/index.action" ).getAction();
58 protected String[] getContextLocations()
60 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
63 public void testGetRepositories()
66 MockControl control = MockControl.createControl( MetadataRepository.class );
67 MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
68 control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
69 Arrays.asList( "20091125.123456.678" ) );
70 control.expectAndReturn(
71 metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
72 new RepositoryStatistics() );
73 control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
74 Arrays.asList( "20091112.012345.012" ) );
75 control.expectAndReturn(
76 metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID, "20091112.012345.012" ),
77 new RepositoryStatistics() );
80 RepositorySession session = mock( RepositorySession.class );
81 when( session.getRepository() ).thenReturn( metadataRepository );
82 TestRepositorySessionFactory factory =
83 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
84 factory.setRepositorySession( session );
86 ServletRunner sr = new ServletRunner();
87 ServletUnitClient sc = sr.newClient();
89 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() );