1 package org.apache.archiva.web.action;
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.opensymphony.xwork2.ActionContext;
23 import com.opensymphony.xwork2.config.Configuration;
24 import com.opensymphony.xwork2.config.ConfigurationManager;
25 import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
26 import com.opensymphony.xwork2.inject.Container;
27 import com.opensymphony.xwork2.util.ValueStack;
28 import com.opensymphony.xwork2.util.ValueStackFactory;
29 import org.apache.archiva.metadata.generic.GenericMetadataFacet;
30 import org.apache.archiva.metadata.model.CiManagement;
31 import org.apache.archiva.metadata.model.IssueManagement;
32 import org.apache.archiva.metadata.model.License;
33 import org.apache.archiva.metadata.model.Organization;
34 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
35 import org.apache.archiva.metadata.model.Scm;
36 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
37 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
38 import org.apache.archiva.security.UserRepositoriesStub;
39 import org.apache.archiva.webtest.memory.TestMetadataResolver;
40 import org.apache.jackrabbit.api.JackrabbitRepository;
41 import org.apache.struts2.StrutsSpringTestCase;
43 import java.util.HashMap;
44 import java.util.List;
46 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
47 import org.junit.After;
48 import org.junit.Before;
49 import org.junit.runner.RunWith;
50 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
51 public abstract class AbstractActionTestCase
52 extends StrutsSpringTestCase
54 protected static final String TEST_REPO = "test-repo";
56 protected TestMetadataResolver metadataResolver;
58 protected static final String TEST_GROUP_ID = "groupId";
60 protected static final String TEST_ARTIFACT_ID = "artifactId";
62 protected static final String TEST_PACKAGING = "packaging";
64 protected static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM";
66 protected static final String TEST_ISSUE_SYSTEM = "jira";
68 protected static final String TEST_CI_SYSTEM = "continuum";
70 protected static final String TEST_CI_URL = "http://vmbuild.apache.org/";
72 protected static final String TEST_URL = "url";
74 protected static final String TEST_NAME = "name";
76 protected static final String TEST_DESCRIPTION = "description";
78 protected static final String TEST_PARENT_GROUP_ID = "parentGroupId";
80 protected static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId";
82 protected static final String TEST_PARENT_VERSION = "parentVersion";
84 protected static final String TEST_ORGANIZATION_NAME = "organizationName";
86 protected static final String TEST_ORGANIZATION_URL = "organizationUrl";
88 protected static final String TEST_LICENSE_URL = "licenseUrl";
90 protected static final String TEST_LICENSE_NAME = "licenseName";
92 protected static final String TEST_LICENSE_URL_2 = "licenseUrl_2";
94 protected static final String TEST_LICENSE_NAME_2 = "licenseName_2";
96 protected static final String TEST_SCM_CONNECTION = "scmConnection";
98 protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
100 protected static final String TEST_SCM_URL = "scmUrl";
102 protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating";
104 protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars";
107 protected String[] getContextLocations( )
109 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
112 protected void setObservableRepos( List<String> repoIds )
114 UserRepositoriesStub repos = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
115 repos.setObservableRepositoryIds( repoIds );
118 protected void assertDefaultModel( ProjectVersionMetadata model, String version )
120 assertDefaultModel( model, TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
123 protected void assertDefaultModel( ProjectVersionMetadata model, String groupId, String artifactId, String version )
125 assertEquals( version, model.getVersion( ) );
126 assertEquals( TEST_URL, model.getUrl( ) );
127 assertEquals( TEST_NAME, model.getName( ) );
128 assertEquals( TEST_DESCRIPTION, model.getDescription( ) );
129 assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization( ).getName( ) );
130 assertEquals( TEST_ORGANIZATION_URL, model.getOrganization( ).getUrl( ) );
131 assertEquals( 2, model.getLicenses( ).size( ) );
132 License l = model.getLicenses( ).get( 0 );
133 assertEquals( TEST_LICENSE_NAME, l.getName( ) );
134 assertEquals( TEST_LICENSE_URL, l.getUrl( ) );
135 l = model.getLicenses( ).get( 1 );
136 assertEquals( TEST_LICENSE_NAME_2, l.getName( ) );
137 assertEquals( TEST_LICENSE_URL_2, l.getUrl( ) );
138 assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement( ).getSystem( ) );
139 assertEquals( TEST_ISSUE_URL, model.getIssueManagement( ).getUrl( ) );
140 assertEquals( TEST_CI_SYSTEM, model.getCiManagement( ).getSystem( ) );
141 assertEquals( TEST_CI_URL, model.getCiManagement( ).getUrl( ) );
142 assertEquals( TEST_SCM_CONNECTION, model.getScm( ).getConnection( ) );
143 assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm( ).getDeveloperConnection( ) );
144 assertEquals( TEST_SCM_URL, model.getScm( ).getUrl( ) );
146 MavenProjectFacet mavenFacet = (MavenProjectFacet) model.getFacet( MavenProjectFacet.FACET_ID );
147 assertEquals( groupId, mavenFacet.getGroupId( ) );
148 assertEquals( artifactId, mavenFacet.getArtifactId( ) );
149 assertEquals( TEST_PACKAGING, mavenFacet.getPackaging( ) );
150 assertEquals( TEST_PARENT_GROUP_ID, mavenFacet.getParent( ).getGroupId( ) );
151 assertEquals( TEST_PARENT_ARTIFACT_ID, mavenFacet.getParent( ).getArtifactId( ) );
152 assertEquals( TEST_PARENT_VERSION, mavenFacet.getParent( ).getVersion( ) );
155 protected ProjectVersionMetadata createProjectModel( String version )
157 return createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
160 protected ProjectVersionMetadata createProjectModel( String groupId, String artifactId, String version )
162 ProjectVersionMetadata model = new ProjectVersionMetadata( );
163 model.setId( version );
164 model.setUrl( TEST_URL );
165 model.setName( TEST_NAME );
166 model.setDescription( TEST_DESCRIPTION );
167 CiManagement ci = new CiManagement( );
168 ci.setSystem( TEST_CI_SYSTEM );
169 ci.setUrl( TEST_CI_URL );
170 model.setCiManagement( ci );
171 IssueManagement issue = new IssueManagement( );
172 issue.setSystem( TEST_ISSUE_SYSTEM );
173 issue.setUrl( TEST_ISSUE_URL );
174 model.setIssueManagement( issue );
175 Organization organization = new Organization( );
176 organization.setName( TEST_ORGANIZATION_NAME );
177 organization.setUrl( TEST_ORGANIZATION_URL );
178 model.setOrganization( organization );
179 License l = new License( );
180 l.setName( TEST_LICENSE_NAME );
181 l.setUrl( TEST_LICENSE_URL );
182 model.addLicense( l );
184 l.setName( TEST_LICENSE_NAME_2 );
185 l.setUrl( TEST_LICENSE_URL_2 );
186 model.addLicense( l );
187 Scm scm = new Scm( );
188 scm.setConnection( TEST_SCM_CONNECTION );
189 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
190 scm.setUrl( TEST_SCM_URL );
193 MavenProjectFacet mavenProjectFacet = new MavenProjectFacet( );
194 mavenProjectFacet.setGroupId( groupId );
195 mavenProjectFacet.setArtifactId( artifactId );
196 mavenProjectFacet.setPackaging( TEST_PACKAGING );
197 MavenProjectParent parent = new MavenProjectParent( );
198 parent.setGroupId( TEST_PARENT_GROUP_ID );
199 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
200 parent.setVersion( TEST_PARENT_VERSION );
201 mavenProjectFacet.setParent( parent );
202 model.addFacet( mavenProjectFacet );
204 GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet( );
205 Map<String, String> props = new HashMap<String, String>( );
206 props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE );
207 genericMetadataFacet.setAdditionalProperties( props );
208 model.addFacet( genericMetadataFacet );
220 ConfigurationManager configurationManager = new ConfigurationManager( );
221 configurationManager.addContainerProvider( new XWorkConfigurationProvider( ) );
222 Configuration config = configurationManager.getConfiguration( );
223 Container container = config.getContainer( );
225 ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack( );
226 stack.getContext( ).put( ActionContext.CONTAINER, container );
227 ActionContext.setContext( new ActionContext( stack.getContext( ) ) );
232 public void tearDown( )
236 applicationContext.getBean( JackrabbitRepository.class ).shutdown( );