From 5e5764c8a09b44a6b3946735a8b26c7e397e9336 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 10 Dec 2009 11:41:18 +0000 Subject: [PATCH] [MRM-1025] remove constraint that is no longer used git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@889205 13f79535-47bb-0310-9956-ffa450edef68 --- .../constraints/UniqueVersionConstraint.java | 120 ----------- .../UniqueVersionConstraintTest.java | 193 ------------------ .../admin/repositories/ArchivaDAOStub.java | 16 +- 3 files changed, 1 insertion(+), 328 deletions(-) delete mode 100644 archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraint.java delete mode 100644 archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraintTest.java diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraint.java deleted file mode 100644 index 9149f4449..000000000 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraint.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.apache.maven.archiva.database.constraints; - -/* - * 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.commons.lang.StringUtils; -import org.apache.maven.archiva.database.Constraint; -import org.apache.maven.archiva.model.ArchivaArtifactModel; - -import java.util.List; - -/** - * Obtain the list of version's for specific GroupId and ArtifactId. - * - * @version $Id$ - */ -public class UniqueVersionConstraint - extends AbstractSimpleConstraint - implements Constraint -{ - private StringBuffer sql = new StringBuffer(); - - /** - * Obtain the list of version's for specific GroupId and ArtifactId. - * - * @param selectedRepositoryIds the selected repository ids. - * @param groupId the selected groupId. - * @param artifactId the selected artifactId. - */ - public UniqueVersionConstraint( List selectedRepositoryIds, String groupId, String artifactId ) - { - if ( StringUtils.isBlank( groupId ) ) - { - throw new IllegalArgumentException( "A blank groupId is not allowed." ); - } - - if ( StringUtils.isBlank( artifactId ) ) - { - throw new IllegalArgumentException( "A blank artifactId is not allowed." ); - } - - appendSelect( sql ); - sql.append( " WHERE " ); - SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositoryIds ); - sql.append( " && " ); - appendWhereSelectedGroupIdArtifactId( sql ); - appendGroupBy( sql ); - - super.params = new Object[] { groupId, artifactId }; - } - - /** - * Obtain the list of version's for specific GroupId and ArtifactId. - * - * @param groupId the selected groupId. - * @param artifactId the selected artifactId. - */ - public UniqueVersionConstraint( String groupId, String artifactId ) - { - if ( StringUtils.isBlank( groupId ) ) - { - throw new IllegalArgumentException( "A blank groupId is not allowed." ); - } - - if ( StringUtils.isBlank( artifactId ) ) - { - throw new IllegalArgumentException( "A blank artifactId is not allowed." ); - } - - appendSelect( sql ); - sql.append( " WHERE " ); - appendWhereSelectedGroupIdArtifactId( sql ); - appendGroupBy( sql ); - - super.params = new Object[] { groupId, artifactId }; - } - - @SuppressWarnings("unchecked") - public Class getResultClass() - { - return String.class; - } - - public String getSelectSql() - { - return sql.toString(); - } - - private void appendGroupBy( StringBuffer buf ) - { - buf.append( " GROUP BY version ORDER BY version ASCENDING" ); - } - - private void appendSelect( StringBuffer buf ) - { - buf.append( "SELECT version FROM " ).append( ArchivaArtifactModel.class.getName() ); - } - - private void appendWhereSelectedGroupIdArtifactId( StringBuffer buf ) - { - buf.append( " groupId == selectedGroupId && artifactId == selectedArtifactId" ); - buf.append( " PARAMETERS String selectedGroupId, String selectedArtifactId" ); - } -} diff --git a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraintTest.java b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraintTest.java deleted file mode 100644 index 4d12bf49c..000000000 --- a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/UniqueVersionConstraintTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.apache.maven.archiva.database.constraints; - -/* - * 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.commons.lang.StringUtils; -import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; -import org.apache.maven.archiva.database.ArchivaDAO; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.SimpleConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -/** - * UniqueVersionConstraintTest - * - * @version $Id$ - */ -public class UniqueVersionConstraintTest - extends AbstractArchivaDatabaseTestCase -{ - private ArtifactDAO artifactDao; - - public void testConstraintGroupIdArtifactIdCommonsLang() - throws Exception - { - setupArtifacts(); - - assertConstraint( new String[] { "2.0", "2.1" }, new UniqueVersionConstraint( "commons-lang", "commons-lang" ) ); - } - - public void testConstraintGroupIdArtifactIdInvalid() - throws Exception - { - setupArtifacts(); - - assertConstraint( new String[] {}, new UniqueVersionConstraint( "org.apache", "invalid" ) ); - assertConstraint( new String[] {}, new UniqueVersionConstraint( "org.apache.test", "invalid" ) ); - assertConstraint( new String[] {}, new UniqueVersionConstraint( "invalid", "test-two" ) ); - } - - public void testConstraintGroupIdArtifactIdMavenSharedTestTwo() - throws Exception - { - setupArtifacts(); - - assertConstraint( new String[] { "2.0", "2.1-SNAPSHOT", "2.1.1", "2.1-alpha-1" }, - new UniqueVersionConstraint( "org.apache.maven.shared", "test-two" ) ); - } - - public void testConstraintGroupIdArtifactIdMavenSharedTestTwoCentralOnly() - throws Exception - { - setupArtifacts(); - - List observableRepositories = new ArrayList(); - observableRepositories.add( "central" ); - - assertConstraint( new String[] { "2.0", "2.1.1", "2.1-alpha-1" }, - new UniqueVersionConstraint( observableRepositories, "org.apache.maven.shared", "test-two" ) ); - } - - public void testConstraintGroupIdArtifactIdMavenSharedTestTwoSnapshotsOnly() - throws Exception - { - setupArtifacts(); - - List observableRepositories = new ArrayList(); - observableRepositories.add( "snapshots" ); - - assertConstraint( new String[] { "2.1-SNAPSHOT" }, - new UniqueVersionConstraint( observableRepositories, "org.apache.maven.shared", "test-two" ) ); - } - - public void testConstraintGroupIdArtifactIdMavenTestOne() - throws Exception - { - setupArtifacts(); - - assertConstraint( new String[] { "1.2" }, new UniqueVersionConstraint( "org.apache.maven.test", "test-one" ) ); - } - - public void testConstraintGroupIdArtifactIdModelloLong() - throws Exception - { - setupArtifacts(); - - assertConstraint( new String[] { "3.0" }, new UniqueVersionConstraint( "org.codehaus.modello", "modellong" ) ); - } - - @SuppressWarnings("unchecked") - private void assertConstraint( String[] versions, SimpleConstraint constraint ) - { - String prefix = "Unique Versions: "; - - List results = (List) dao.query( constraint ); - assertNotNull( prefix + "Not Null", results ); - assertEquals( prefix + "Results.size", versions.length, results.size() ); - - List expectedVersions = Arrays.asList( versions ); - - for ( String actualVersion : results ) - { - assertTrue( prefix + "version result should not be blank.", StringUtils.isNotBlank( actualVersion ) ); - assertTrue( prefix + "version result <" + actualVersion + "> exists in expected versions.", - expectedVersions.contains( actualVersion ) ); - } - } - - private ArchivaArtifact createArtifact( String repoId, String groupId, String artifactId, String version ) - { - ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar", "testrepo" ); - artifact.getModel().setLastModified( new Date() ); // mandatory field. - artifact.getModel().setRepositoryId( repoId ); - return artifact; - } - - private void setupArtifacts() - throws Exception - { - ArchivaArtifact artifact; - - // Setup artifacts in fresh DB. - artifact = createArtifact( "central", "commons-lang", "commons-lang", "2.0" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "commons-lang", "commons-lang", "2.1" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.test", "test-one", "1.2" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.test.foo", "test-two", "1.0" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.shared", "test-two", "2.0" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.shared", "test-two", "2.1.1" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.shared", "test-two", "2.1-alpha-1" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.apache.maven.shared", "test-bar", "2.1" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "central", "org.codehaus.modello", "modellong", "3.0" ); - artifactDao.saveArtifact( artifact ); - - // Snapshots repository artifacts - artifact = createArtifact( "snapshots", "org.apache.maven.shared", "test-two", "2.1-SNAPSHOT" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "snapshots", "org.codehaus.modello", "test-three", "1.0-SNAPSHOT" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "snapshots", "org.codehaus.mojo", "testable-maven-plugin", "2.1-SNAPSHOT" ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "snapshots", "org.apache.archiva", "testable", "1.1-alpha-1-20070822.033400-43" ); - artifactDao.saveArtifact( artifact ); - } - - protected void setUp() - throws Exception - { - super.setUp(); - - ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" ); - artifactDao = dao.getArtifactDAO(); - } -} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java index 3553dcd8c..7692ba147 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java @@ -21,13 +21,11 @@ package org.apache.maven.archiva.web.action.admin.repositories; import java.util.List; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; import org.apache.maven.archiva.database.constraints.UniqueFieldConstraint; -import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; /** * Stub class for Archiva DAO to avoid having to set up a database for tests. @@ -37,23 +35,16 @@ import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; public class ArchivaDAOStub implements ArchivaDAO { - private ArchivaConfiguration configuration; private ArtifactDAO artifactDao; - private List versions; - private List repositoryIds; private RepositoryProblemDAO repositoryProblemDAO; public List query( SimpleConstraint constraint ) { - if ( constraint instanceof UniqueVersionConstraint ) - { - return versions; - } - else if ( constraint instanceof UniqueFieldConstraint ) + if ( constraint instanceof UniqueFieldConstraint ) { return repositoryIds; } @@ -75,11 +66,6 @@ public class ArchivaDAOStub this.artifactDao = artifactDao; } - public void setVersions( List versions ) - { - this.versions = versions; - } - public void setRepositoryIds( List repositoryIds ) { this.repositoryIds = repositoryIds; -- 2.39.5