From c1678e136b0e264d4805a096dcbdd29fb3476684 Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Fri, 2 Dec 2005 01:38:08 +0000 Subject: [PATCH] PR: MRM-50 Submitted by: John Tolentino Additional unit tests git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@351553 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractRepositoryReportsTestCase.java | 81 +++++++++++++++++++ .../DefaultArtifactReporterTest.java | 16 +++- .../DefaultRepositoryQueryLayerTest.java | 9 ++- 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java new file mode 100644 index 000000000..9be7f491f --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java @@ -0,0 +1,81 @@ +package org.apache.maven.repository.reporting; + +/* + * Copyright 2001-2005 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. + */ + +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author John Tolentino + */ +public abstract class AbstractRepositoryReportsTestCase + extends PlexusTestCase +{ + private static String JAR = ".jar"; + + private static String basedir; + + private static String[] directoryStructure; + + public AbstractRepositoryReportsTestCase( String basedir, String[] directoryStructure ) + { + this.basedir = basedir; + this.directoryStructure = directoryStructure; + } + + protected void setUp() + throws Exception + { + super.setUp(); + buildTestRepoPath(); + } + + private void buildTestRepoPath() + { + for ( int i = 0; i < directoryStructure.length; i++ ) + { + File dir = new File( basedir + directoryStructure[i] ); + if ( !dir.exists() ) + { + dir.mkdirs(); + } + } + } + + private void deleteTestRepoPath() throws Exception + { + FileUtils.deleteDirectory( basedir ); + } + + protected boolean writeTestArtifact( String relativePath, String artifactId ) + throws Exception + { + File artifact = new File( basedir + relativePath + artifactId + JAR ); + System.out.println( "" + basedir + relativePath + artifactId ); + return artifact.createNewFile(); + } + + protected void tearDown() + throws Exception + { + deleteTestRepoPath(); + super.tearDown(); + } +} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java index 62ff1cba1..8efee560f 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java @@ -18,16 +18,26 @@ package org.apache.maven.repository.reporting; import org.codehaus.plexus.PlexusTestCase; +import java.io.File; +import java.lang.System; + /** * Test the artifact reporter. * * @author John Tolentino */ public class DefaultArtifactReporterTest - extends PlexusTestCase + extends AbstractRepositoryReportsTestCase { + private static final String[] testRepoStructure = { "valid-poms/", "invalid-poms/" }; + private ArtifactReporter reporter; + public DefaultArtifactReporterTest() + { + super( System.getProperty( "basedir" ) + "/src/test/repository/", testRepoStructure ); + } + protected void setUp() throws Exception { @@ -35,9 +45,9 @@ public class DefaultArtifactReporterTest reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE, "default" ); } - public void testAddSuccess() + public void testAddSuccess() throws Exception { - assertTrue( true ); + assertTrue( writeTestArtifact( "valid-poms/", "test" ) ); } protected void tearDown() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java index f67a67cdd..bbba7ba19 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerTest.java @@ -24,10 +24,17 @@ import org.codehaus.plexus.PlexusTestCase; * @author John Tolentino */ public class DefaultRepositoryQueryLayerTest - extends PlexusTestCase + extends AbstractRepositoryReportsTestCase { + private static final String[] testRepoStructure = { "valid-poms/", "invalid-poms/" }; + private RepositoryQueryLayer queryLayer; + public DefaultRepositoryQueryLayerTest() + { + super( System.getProperty( "basedir" ) + "/src/test/repository/", testRepoStructure ); + } + protected void setUp() throws Exception { -- 2.39.5