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;
47 public abstract class AbstractActionTestCase
48 extends StrutsSpringTestCase
50 protected static final String TEST_REPO = "test-repo";
52 protected TestMetadataResolver metadataResolver;
54 protected static final String TEST_GROUP_ID = "groupId";
56 protected static final String TEST_ARTIFACT_ID = "artifactId";
58 protected static final String TEST_PACKAGING = "packaging";
60 protected static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM";
62 protected static final String TEST_ISSUE_SYSTEM = "jira";
64 protected static final String TEST_CI_SYSTEM = "continuum";
66 protected static final String TEST_CI_URL = "http://vmbuild.apache.org/";
68 protected static final String TEST_URL = "url";
70 protected static final String TEST_NAME = "name";
72 protected static final String TEST_DESCRIPTION = "description";
74 protected static final String TEST_PARENT_GROUP_ID = "parentGroupId";
76 protected static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId";
78 protected static final String TEST_PARENT_VERSION = "parentVersion";
80 protected static final String TEST_ORGANIZATION_NAME = "organizationName";
82 protected static final String TEST_ORGANIZATION_URL = "organizationUrl";
84 protected static final String TEST_LICENSE_URL = "licenseUrl";
86 protected static final String TEST_LICENSE_NAME = "licenseName";
88 protected static final String TEST_LICENSE_URL_2 = "licenseUrl_2";
90 protected static final String TEST_LICENSE_NAME_2 = "licenseName_2";
92 protected static final String TEST_SCM_CONNECTION = "scmConnection";
94 protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
96 protected static final String TEST_SCM_URL = "scmUrl";
98 protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating";
100 protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars";
103 protected String[] getContextLocations( )
105 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
108 protected void setObservableRepos( List<String> repoIds )
110 UserRepositoriesStub repos = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
111 repos.setObservableRepositoryIds( repoIds );
114 protected void assertDefaultModel( ProjectVersionMetadata model, String version )
116 assertDefaultModel( model, TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
119 protected void assertDefaultModel( ProjectVersionMetadata model, String groupId, String artifactId, String version )
121 assertEquals( version, model.getVersion( ) );
122 assertEquals( TEST_URL, model.getUrl( ) );
123 assertEquals( TEST_NAME, model.getName( ) );
124 assertEquals( TEST_DESCRIPTION, model.getDescription( ) );
125 assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization( ).getName( ) );
126 assertEquals( TEST_ORGANIZATION_URL, model.getOrganization( ).getUrl( ) );
127 assertEquals( 2, model.getLicenses( ).size( ) );
128 License l = model.getLicenses( ).get( 0 );
129 assertEquals( TEST_LICENSE_NAME, l.getName( ) );
130 assertEquals( TEST_LICENSE_URL, l.getUrl( ) );
131 l = model.getLicenses( ).get( 1 );
132 assertEquals( TEST_LICENSE_NAME_2, l.getName( ) );
133 assertEquals( TEST_LICENSE_URL_2, l.getUrl( ) );
134 assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement( ).getSystem( ) );
135 assertEquals( TEST_ISSUE_URL, model.getIssueManagement( ).getUrl( ) );
136 assertEquals( TEST_CI_SYSTEM, model.getCiManagement( ).getSystem( ) );
137 assertEquals( TEST_CI_URL, model.getCiManagement( ).getUrl( ) );
138 assertEquals( TEST_SCM_CONNECTION, model.getScm( ).getConnection( ) );
139 assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm( ).getDeveloperConnection( ) );
140 assertEquals( TEST_SCM_URL, model.getScm( ).getUrl( ) );
142 MavenProjectFacet mavenFacet = (MavenProjectFacet) model.getFacet( MavenProjectFacet.FACET_ID );
143 assertEquals( groupId, mavenFacet.getGroupId( ) );
144 assertEquals( artifactId, mavenFacet.getArtifactId( ) );
145 assertEquals( TEST_PACKAGING, mavenFacet.getPackaging( ) );
146 assertEquals( TEST_PARENT_GROUP_ID, mavenFacet.getParent( ).getGroupId( ) );
147 assertEquals( TEST_PARENT_ARTIFACT_ID, mavenFacet.getParent( ).getArtifactId( ) );
148 assertEquals( TEST_PARENT_VERSION, mavenFacet.getParent( ).getVersion( ) );
151 protected ProjectVersionMetadata createProjectModel( String version )
153 return createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
156 protected ProjectVersionMetadata createProjectModel( String groupId, String artifactId, String version )
158 ProjectVersionMetadata model = new ProjectVersionMetadata( );
159 model.setId( version );
160 model.setUrl( TEST_URL );
161 model.setName( TEST_NAME );
162 model.setDescription( TEST_DESCRIPTION );
163 CiManagement ci = new CiManagement( );
164 ci.setSystem( TEST_CI_SYSTEM );
165 ci.setUrl( TEST_CI_URL );
166 model.setCiManagement( ci );
167 IssueManagement issue = new IssueManagement( );
168 issue.setSystem( TEST_ISSUE_SYSTEM );
169 issue.setUrl( TEST_ISSUE_URL );
170 model.setIssueManagement( issue );
171 Organization organization = new Organization( );
172 organization.setName( TEST_ORGANIZATION_NAME );
173 organization.setUrl( TEST_ORGANIZATION_URL );
174 model.setOrganization( organization );
175 License l = new License( );
176 l.setName( TEST_LICENSE_NAME );
177 l.setUrl( TEST_LICENSE_URL );
178 model.addLicense( l );
180 l.setName( TEST_LICENSE_NAME_2 );
181 l.setUrl( TEST_LICENSE_URL_2 );
182 model.addLicense( l );
183 Scm scm = new Scm( );
184 scm.setConnection( TEST_SCM_CONNECTION );
185 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
186 scm.setUrl( TEST_SCM_URL );
189 MavenProjectFacet mavenProjectFacet = new MavenProjectFacet( );
190 mavenProjectFacet.setGroupId( groupId );
191 mavenProjectFacet.setArtifactId( artifactId );
192 mavenProjectFacet.setPackaging( TEST_PACKAGING );
193 MavenProjectParent parent = new MavenProjectParent( );
194 parent.setGroupId( TEST_PARENT_GROUP_ID );
195 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
196 parent.setVersion( TEST_PARENT_VERSION );
197 mavenProjectFacet.setParent( parent );
198 model.addFacet( mavenProjectFacet );
200 GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet( );
201 Map<String, String> props = new HashMap<String, String>( );
202 props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE );
203 genericMetadataFacet.setAdditionalProperties( props );
204 model.addFacet( genericMetadataFacet );
210 protected void setUp( )
215 ConfigurationManager configurationManager = new ConfigurationManager( );
216 configurationManager.addContainerProvider( new XWorkConfigurationProvider( ) );
217 Configuration config = configurationManager.getConfiguration( );
218 Container container = config.getContainer( );
220 ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack( );
221 stack.getContext( ).put( ActionContext.CONTAINER, container );
222 ActionContext.setContext( new ActionContext( stack.getContext( ) ) );
226 protected void tearDown( )
230 applicationContext.getBean( JackrabbitRepository.class ).shutdown( );