You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by jz...@apache.org on 2009/08/27 13:27:33 UTC
svn commit: r808372 - in
/continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action:
AddProjectActionTest.java stub/ stub/AddProjectActionStub.java
Author: jzurbano
Date: Thu Aug 27 11:27:33 2009
New Revision: 808372
URL: http://svn.apache.org/viewvc?rev=808372&view=rev
Log:
[CONTINUUM-2318] - NPE when adding Ant/Shell Projects
- added tests
Added:
continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java (with props)
continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/
continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java (with props)
Added: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java?rev=808372&view=auto
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java (added)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java Thu Aug 27 11:27:33 2009
@@ -0,0 +1,136 @@
+package org.apache.maven.continuum.web.action;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.continuum.web.action.stub.AddProjectActionStub;
+import org.apache.maven.continuum.Continuum;
+import org.apache.maven.continuum.model.project.Project;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * Test for {@link AddProjectAction}
+ *
+ * @author <a href="mailto:jzurbano@apache.org">jzurbano</a>
+ */
+public class AddProjectActionTest
+ extends MockObjectTestCase
+{
+ private final AddProjectActionStub action;
+
+ private final Mock continuumMock;
+
+ public AddProjectActionTest()
+ {
+ action = new AddProjectActionStub();
+ continuumMock = new Mock( Continuum.class );
+ action.setContinuum( (Continuum) continuumMock.proxy() );
+ }
+
+ public void testAddProjectNullValues()
+ throws Exception
+ {
+ action.setProjectName( null );
+ action.setProjectVersion( null );
+ action.setProjectScmUrl( null );
+
+ action.validate();
+ }
+
+ /**
+ * Test add of Ant project
+ *
+ * @throws Exception
+ */
+ public void testAddAntProject()
+ throws Exception
+ {
+ String scmUrl = "scm:svn:http://project/scm/url/test/build.xml";
+
+ List<Project> projects = createProjectList();
+ continuumMock.expects( once() ).method( "getProjects" ).will( returnValue( projects ) );
+ continuumMock.expects( once() ).method( "addProject" ).will( returnValue( 3 ) );
+
+ action.setProjectName( "Ant Test Project" );
+ action.setProjectVersion( "1.0-SNAPSHOT" );
+ action.setProjectScmUrl( scmUrl );
+ action.setProjectType( "ant" );
+ action.setSelectedProjectGroup( 1 );
+ action.setBuildDefintionTemplateId( 1 );
+
+ action.validate();
+ action.add();
+ continuumMock.verify();
+
+ }
+
+ /**
+ * Test add of Shell project
+ *
+ * @throws Exception
+ */
+ public void testAddShellProject()
+ throws Exception
+ {
+ String scmUrl = "scm:svn:http://project/scm/url/test/run.sh";
+
+ List<Project> projects = createProjectList();
+ continuumMock.expects( once() ).method( "getProjects" ).will( returnValue( projects ) );
+ continuumMock.expects( once() ).method( "addProject" ).will( returnValue( 3 ) );
+
+ action.setProjectName( "Shell Test Project" );
+ action.setProjectVersion( "1.0-SNAPSHOT" );
+ action.setProjectScmUrl( scmUrl );
+ action.setProjectType( "shell" );
+ action.setSelectedProjectGroup( 1 );
+ action.setBuildDefintionTemplateId( 1 );
+
+ action.validate();
+ action.add();
+ continuumMock.verify();
+ }
+
+ private List<Project> createProjectList()
+ {
+ List<Project> projects = new ArrayList<Project>();
+
+ Project project1 = createProject( "scm:svn:http://project/scm/url/test-1/run.sh", "Shell Test Project 1", "1.0-SNAPSHOT", 1 );
+ Project project2 = createProject( "scm:svn:http://project/scm/url/test-2/build.xml", "Ant Test Project 1", "1.0-SNAPSHOT", 2 );
+
+ projects.add( project1 );
+ projects.add( project2 );
+
+ return projects;
+ }
+
+ private Project createProject( String scmUrl, String name, String version, int id )
+ {
+ Project project = new Project();
+ project.setId( id );
+ project.setName( name );
+ project.setVersion( version );
+ project.setScmUrl( scmUrl );
+
+ return project;
+ }
+}
Propchange: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/AddProjectActionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java?rev=808372&view=auto
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java (added)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java Thu Aug 27 11:27:33 2009
@@ -0,0 +1,57 @@
+package org.apache.maven.continuum.web.action.stub;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.continuum.web.action.AddProjectAction;
+
+/**
+ * Stub for {@link AddProjectAction}
+ *
+ * @author <a href="mailto:jzurbano@apache.org">jzurbano</a>
+ */
+public class AddProjectActionStub
+ extends AddProjectAction
+{
+ public String input()
+ {
+ return INPUT;
+ }
+
+ private void initializeProjectGroupName()
+ {
+ setProjectGroupName( "Test Project Group" );
+ }
+
+ private boolean isAuthorizedToAddProjectToGroup( String projectGroupName )
+ {
+ return true;
+ }
+
+ protected void checkAddProjectGroupAuthorization()
+ {
+ // skip authorization check
+ }
+
+ protected void checkAddProjectToGroupAuthorization( String projectGroupName )
+ {
+ // skip authorization check
+ }
+}
+
Propchange: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/AddProjectActionStub.java
------------------------------------------------------------------------------
svn:eol-style = native