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.webtest.memory.TestMetadataResolver;
37 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
38 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
39 import org.apache.archiva.security.UserRepositoriesStub;
40 import org.apache.struts2.StrutsSpringTestCase;
42 import java.util.HashMap;
43 import java.util.List;
46 public abstract class AbstractActionTestCase
47 extends StrutsSpringTestCase
49 protected static final String TEST_REPO = "test-repo";
51 protected TestMetadataResolver metadataResolver;
53 protected static final String TEST_GROUP_ID = "groupId";
55 protected static final String TEST_ARTIFACT_ID = "artifactId";
57 protected static final String TEST_PACKAGING = "packaging";
59 protected static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM";
61 protected static final String TEST_ISSUE_SYSTEM = "jira";
63 protected static final String TEST_CI_SYSTEM = "continuum";
65 protected static final String TEST_CI_URL = "http://vmbuild.apache.org/";
67 protected static final String TEST_URL = "url";
69 protected static final String TEST_NAME = "name";
71 protected static final String TEST_DESCRIPTION = "description";
73 protected static final String TEST_PARENT_GROUP_ID = "parentGroupId";
75 protected static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId";
77 protected static final String TEST_PARENT_VERSION = "parentVersion";
79 protected static final String TEST_ORGANIZATION_NAME = "organizationName";
81 protected static final String TEST_ORGANIZATION_URL = "organizationUrl";
83 protected static final String TEST_LICENSE_URL = "licenseUrl";
85 protected static final String TEST_LICENSE_NAME = "licenseName";
87 protected static final String TEST_LICENSE_URL_2 = "licenseUrl_2";
89 protected static final String TEST_LICENSE_NAME_2 = "licenseName_2";
91 protected static final String TEST_SCM_CONNECTION = "scmConnection";
93 protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
95 protected static final String TEST_SCM_URL = "scmUrl";
97 protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating";
99 protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars";
102 protected String[] getContextLocations()
104 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
107 protected void setObservableRepos( List<String> repoIds )
109 UserRepositoriesStub repos = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
110 repos.setObservableRepositoryIds( repoIds );
113 protected void assertDefaultModel( ProjectVersionMetadata model, String version )
115 assertDefaultModel( model, TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
118 protected void assertDefaultModel( ProjectVersionMetadata model, String groupId, String artifactId, String version )
120 assertEquals( version, model.getVersion() );
121 assertEquals( TEST_URL, model.getUrl() );
122 assertEquals( TEST_NAME, model.getName() );
123 assertEquals( TEST_DESCRIPTION, model.getDescription() );
124 assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() );
125 assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() );
126 assertEquals( 2, model.getLicenses().size() );
127 License l = model.getLicenses().get( 0 );
128 assertEquals( TEST_LICENSE_NAME, l.getName() );
129 assertEquals( TEST_LICENSE_URL, l.getUrl() );
130 l = model.getLicenses().get( 1 );
131 assertEquals( TEST_LICENSE_NAME_2, l.getName() );
132 assertEquals( TEST_LICENSE_URL_2, l.getUrl() );
133 assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() );
134 assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() );
135 assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() );
136 assertEquals( TEST_CI_URL, model.getCiManagement().getUrl() );
137 assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() );
138 assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() );
139 assertEquals( TEST_SCM_URL, model.getScm().getUrl() );
141 MavenProjectFacet mavenFacet = (MavenProjectFacet) model.getFacet( MavenProjectFacet.FACET_ID );
142 assertEquals( groupId, mavenFacet.getGroupId() );
143 assertEquals( artifactId, mavenFacet.getArtifactId() );
144 assertEquals( TEST_PACKAGING, mavenFacet.getPackaging() );
145 assertEquals( TEST_PARENT_GROUP_ID, mavenFacet.getParent().getGroupId() );
146 assertEquals( TEST_PARENT_ARTIFACT_ID, mavenFacet.getParent().getArtifactId() );
147 assertEquals( TEST_PARENT_VERSION, mavenFacet.getParent().getVersion() );
150 protected ProjectVersionMetadata createProjectModel( String version )
152 return createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
155 protected ProjectVersionMetadata createProjectModel( String groupId, String artifactId, String version )
157 ProjectVersionMetadata model = new ProjectVersionMetadata();
158 model.setId( version );
159 model.setUrl( TEST_URL );
160 model.setName( TEST_NAME );
161 model.setDescription( TEST_DESCRIPTION );
162 CiManagement ci = new CiManagement();
163 ci.setSystem( TEST_CI_SYSTEM );
164 ci.setUrl( TEST_CI_URL );
165 model.setCiManagement( ci );
166 IssueManagement issue = new IssueManagement();
167 issue.setSystem( TEST_ISSUE_SYSTEM );
168 issue.setUrl( TEST_ISSUE_URL );
169 model.setIssueManagement( issue );
170 Organization organization = new Organization();
171 organization.setName( TEST_ORGANIZATION_NAME );
172 organization.setUrl( TEST_ORGANIZATION_URL );
173 model.setOrganization( organization );
174 License l = new License();
175 l.setName( TEST_LICENSE_NAME );
176 l.setUrl( TEST_LICENSE_URL );
177 model.addLicense( l );
179 l.setName( TEST_LICENSE_NAME_2 );
180 l.setUrl( TEST_LICENSE_URL_2 );
181 model.addLicense( l );
183 scm.setConnection( TEST_SCM_CONNECTION );
184 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
185 scm.setUrl( TEST_SCM_URL );
188 MavenProjectFacet mavenProjectFacet = new MavenProjectFacet();
189 mavenProjectFacet.setGroupId( groupId );
190 mavenProjectFacet.setArtifactId( artifactId );
191 mavenProjectFacet.setPackaging( TEST_PACKAGING );
192 MavenProjectParent parent = new MavenProjectParent();
193 parent.setGroupId( TEST_PARENT_GROUP_ID );
194 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
195 parent.setVersion( TEST_PARENT_VERSION );
196 mavenProjectFacet.setParent( parent );
197 model.addFacet( mavenProjectFacet );
199 GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet();
200 Map<String, String> props = new HashMap<String, String>();
201 props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE );
202 genericMetadataFacet.setAdditionalProperties( props );
203 model.addFacet( genericMetadataFacet );
209 protected void setUp()
214 ConfigurationManager configurationManager = new ConfigurationManager();
215 configurationManager.addContainerProvider( new XWorkConfigurationProvider() );
216 Configuration config = configurationManager.getConfiguration();
217 Container container = config.getContainer();
219 ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack();
220 stack.getContext().put( ActionContext.CONTAINER, container );
221 ActionContext.setContext( new ActionContext( stack.getContext() ) );