From 8f8b59ff02852bdedcad4f22950144e87434c8cc Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Mon, 5 Dec 2005 01:20:32 +0000 Subject: [PATCH] Added some unit test objects git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@353953 13f79535-47bb-0310-9956-ffa450edef68 --- maven-repository-reports-standard/pom.xml | 14 ++++ .../AbstractRepositoryReportsTestCase.java | 3 +- .../BadMetadataReportProcessorTest.java | 80 +++++++++++++++++++ .../reporting/GenericMockObject.java | 61 ++++++++++++++ .../TestBadMetadataReportProcessor.java | 29 +++++++ 5 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java create mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java create mode 100644 maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java diff --git a/maven-repository-reports-standard/pom.xml b/maven-repository-reports-standard/pom.xml index cf40cc4db..90918df5b 100755 --- a/maven-repository-reports-standard/pom.xml +++ b/maven-repository-reports-standard/pom.xml @@ -40,4 +40,18 @@ --> + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/Abstract*.java + **/Test*.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 index 9be7f491f..22560cc21 100644 --- 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 @@ -17,9 +17,8 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.codehaus.plexus.PlexusTestCase; - import java.io.File; +import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; /** diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java new file mode 100644 index 000000000..0022e35b7 --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java @@ -0,0 +1,80 @@ +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 java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.codehaus.plexus.PlexusTestCase; + +public class BadMetadataReportProcessorTest extends PlexusTestCase +{ + protected ArtifactFactory artifactFactory; + private BadMetadataReportProcessor badMetadataReportProcessor; + + public BadMetadataReportProcessorTest(String testName) + { + super(testName); + } + + protected void setUp() throws Exception + { + artifactFactory = (ArtifactFactory) getContainer().lookup( ArtifactFactory.ROLE ); + + badMetadataReportProcessor = new TestBadMetadataReportProcessor( artifactFactory, + new DefaultRepositoryQueryLayer() ); + } + + protected RepositoryQueryLayer getRepositoryQueryLayer( List returnValues ) throws NoSuchMethodException + { + GenericMockObject mockObject = new GenericMockObject(); + Method method = RepositoryQueryLayer.class.getMethod( "containsArtifact", null ); + mockObject.setExpectedReturns( method, returnValues ); + RepositoryQueryLayer queryLayer = (RepositoryQueryLayer) Proxy.newProxyInstance( this.getClassLoader(), + new Class[] { RepositoryQueryLayer.class }, + new GenericMockObject() ); + return queryLayer; + } + + protected void tearDown() throws Exception + { + release( artifactFactory ); + } + + public void testProcessMetadata() + { + } + + public void testCheckPluginMetadata() + { + } + + public void testCheckSnapshotMetadata() + { + } + + public void testCheckMetadataVersions() + { + } + + public void testCheckRepositoryVersions() + { + } + +} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java new file mode 100644 index 000000000..44c42add0 --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java @@ -0,0 +1,61 @@ +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 java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.maven.artifact.Artifact; + +/** + * + * @author Edwin Punzalan + */ +public class GenericMockObject implements InvocationHandler +{ + Map invocations = new HashMap(); + + public GenericMockObject() + { + //default constructor + } + + public GenericMockObject( Map returnMap ) + { + invocations = returnMap; + } + + public void setExpectedReturns( Method method, List returnList ) + { + invocations.put( method, returnList ); + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + { + if ( !invocations.containsKey( method ) ) + throw new UnsupportedOperationException( "No expected return values defined." ); + + List returnList = (List) invocations.get( method ); + if ( returnList.size() < 1 ) throw new UnsupportedOperationException( "Too few expected return values defined." ); + return returnList.remove( 0 ); + } +} diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java new file mode 100644 index 000000000..40898528d --- /dev/null +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/TestBadMetadataReportProcessor.java @@ -0,0 +1,29 @@ +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.apache.maven.artifact.factory.ArtifactFactory; + +public class TestBadMetadataReportProcessor extends BadMetadataReportProcessor +{ + public TestBadMetadataReportProcessor( ArtifactFactory factory, RepositoryQueryLayer layer ) + { + artifactFactory = factory ; + repositoryQueryLayer = layer ; + } +}