You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by pt...@apache.org on 2009/01/06 16:31:49 UTC
svn commit: r731973 - in
/jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test:
ArtifactStub.java CactifyMavenProjectStub.java TestCactifyEarMojo.java
Author: ptahchiev
Date: Tue Jan 6 07:31:48 2009
New Revision: 731973
URL: http://svn.apache.org/viewvc?rev=731973&view=rev
Log:
Added artifactStub and CactifyMavenProjectStub to avoid the missing project when testing the war and ear mojos.
Added:
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/ArtifactStub.java
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/CactifyMavenProjectStub.java
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyEarMojo.java
Added: jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/ArtifactStub.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/ArtifactStub.java?rev=731973&view=auto
==============================================================================
--- jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/ArtifactStub.java (added)
+++ jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/ArtifactStub.java Tue Jan 6 07:31:48 2009
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.cactus.integration.maven2.test;
+
+import java.io.File;
+
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ArtifactStub
+ extends DefaultArtifact
+{
+ public ArtifactStub( String groupId, String artifactId, String version, String packaging, String scope )
+ {
+ this( groupId, artifactId, version, packaging, null, scope );
+ }
+
+ public ArtifactStub( String groupId, String artifactId, String version, String packaging, String classifier, String scope )
+ {
+ super( groupId, artifactId, VersionRange.createFromVersion( version ), scope, packaging,
+ classifier, new DefaultArtifactHandler( packaging ), false );
+ }
+
+ public File getFile()
+ {
+ return new File( PlexusTestCase.getBasedir() + "/target/local-repo", getArtifactId() + "-" + getVersion() + "." + getType() )
+ {
+ public long lastModified()
+ {
+ return System.currentTimeMillis();
+ }
+ };
+ }
+}
Added: jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/CactifyMavenProjectStub.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/CactifyMavenProjectStub.java?rev=731973&view=auto
==============================================================================
--- jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/CactifyMavenProjectStub.java (added)
+++ jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/CactifyMavenProjectStub.java Tue Jan 6 07:31:48 2009
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.cactus.integration.maven2.test;
+
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Build;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.util.Set;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.List;
+import java.io.File;
+
+public class CactifyMavenProjectStub extends MavenProjectStub
+{
+
+ private String groupId, artifactId, version;
+
+ private Artifact artifact;
+
+ private Set artifacts;
+
+ private Model model;
+
+ private File basedir;
+
+ public Build getBuild()
+ {
+ return model.getBuild();
+ }
+
+ public List getRemoteArtifactRepositories()
+ {
+ ArtifactRepository repository = new DefaultArtifactRepository( "central",
+ "file://" + PlexusTestCase.getBasedir() + "/src/test/remote-repo",
+ new DefaultRepositoryLayout() );
+
+ return Collections.singletonList( repository );
+ }
+
+ public CactifyMavenProjectStub()
+ {
+ groupId = "cactify";
+ artifactId = "test-project";
+ version = "1.0";
+ }
+
+ public Set getDependencyArtifacts()
+ {
+ return Collections.singleton(
+ new DefaultArtifact( "cactify", "dependency-artifact", VersionRange.createFromVersion( "1.0" ),
+ Artifact.SCOPE_COMPILE, "jar", null, new DefaultArtifactHandler( "jar" ), false )
+ );
+ }
+
+ public File getBasedir()
+ {
+ if ( basedir == null )
+ {
+ basedir = new File( PlexusTestCase.getBasedir() );
+ }
+
+ return basedir;
+ }
+
+ public Artifact getArtifact()
+ {
+ if ( artifact == null )
+ {
+ artifact = new ArtifactStub( groupId, artifactId, version, "jar", Artifact.SCOPE_COMPILE );
+ }
+
+ return artifact;
+ }
+
+ public Model getModel()
+ {
+ if ( model == null )
+ {
+ model = new Model();
+
+ model.setProperties( new Properties() );
+
+ model.setGroupId( getGroupId() );
+
+ model.setArtifactId( getArtifactId() );
+
+ model.setVersion( getVersion() );
+
+ Build build = new Build();
+ build.setFinalName( getArtifactId() + "-" + getVersion() );
+ model.setBuild( build );
+ }
+
+ return model;
+ }
+
+ public Set getArtifacts()
+ {
+ if ( artifacts == null )
+ {
+ artifacts = Collections.EMPTY_SET;
+ }
+
+ return artifacts;
+ }
+
+ public void setArtifacts( Set artifacts )
+ {
+ this.artifacts = artifacts;
+ }
+
+ public Properties getProperties()
+ {
+ return new Properties();
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
+}
Added: jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyEarMojo.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyEarMojo.java?rev=731973&view=auto
==============================================================================
--- jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyEarMojo.java (added)
+++ jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyEarMojo.java Tue Jan 6 07:31:48 2009
@@ -0,0 +1,72 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.integration.maven2.test;
+
+import java.io.File;
+
+import org.apache.cactus.maven2.mojos.CactifyEarMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Some unit tests for the <code>CactifyEarMojo</code> class.
+ *
+ * @author ptahchiev
+ */
+public class TestCactifyEarMojo extends AbstractMojoTestCase
+{
+ /**
+ * The cactifyEarMojo instance.
+ */
+ private CactifyEarMojo cactifyEarMojo;
+
+ /**
+ * Set-up method to instantiate the mojo.
+ */
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.cactifyEarMojo = new CactifyEarMojo();
+ }
+
+
+ /**
+ * Tests the mojo with absolutely no parameters specified
+ * @throws Exception in case some error occurs
+ */
+ public void testCactifyEarWithNoParametersSpecified() throws Exception
+ {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/ear/basic-"
+ + "cactify-noparameters/plugin-config.xml");
+ CactifyEarMojo mojo = (CactifyEarMojo) lookupMojo("cactifyear", testPom);
+ assertNotNull(mojo);
+ try
+ {
+ mojo.execute();
+ fail("Exception should have been raised!");
+ }
+ catch (MojoExecutionException mex)
+ {
+ assertEquals("You need to specify [srcFile] for cactification!", mex.getMessage());
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org