From c65b10563e2519cdec0d74804cfd30521731e634 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Thu, 15 May 2008 08:46:12 +0000 Subject: [PATCH] [MRM-773] -query only versions of artifacts with whenGathered != null -created test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@656552 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArtifactVersionsConstraint.java | 9 +- .../ArtifactVersionsConstraintTest.java | 107 ++++++++++++++++++ .../apache/archiva/rss/RssFeedGenerator.java | 1 - 3 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java index fc976e356..c7eee23a5 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java @@ -36,16 +36,17 @@ public class ArtifactVersionsConstraint private String sortColumn = "repositoryId"; public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId ) - { + { if( repoId != null ) - { - whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId)"; + { + whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " + + "&& whenGathered != null"; declParams = new String[] { "String selectedRepoId", "String selectedGroupId", "String selectedArtifactId" }; params = new Object[] { repoId, groupId, artifactId }; } else { - whereClause = "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId)"; + whereClause = "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) && this.whenGathered != null"; declParams = new String[] { "String selectedGroupId", "String selectedArtifactId" }; params = new Object[] { groupId, artifactId }; } diff --git a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java new file mode 100644 index 000000000..f7fa5b4ff --- /dev/null +++ b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java @@ -0,0 +1,107 @@ +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 java.util.Calendar; +import java.util.Date; +import java.util.List; + +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.model.ArchivaArtifact; + +/** + * ArtifactVersionsConstraintTest + * + * @author Maria Odea Ching + * @version + */ +public class ArtifactVersionsConstraintTest + extends AbstractArchivaDatabaseTestCase +{ + private ArtifactDAO artifactDao; + + public static final String TEST_REPO = "test-repo"; + + public void setUp() + throws Exception + { + super.setUp(); + + ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" ); + artifactDao = dao.getArtifactDAO(); + } + + private ArchivaArtifact createArtifact( String groupId, String artifactId, String version ) + { + ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, null, "jar" ); + artifact.getModel().setLastModified( new Date() ); + artifact.getModel().setRepositoryId( TEST_REPO ); + + return artifact; + } + + private void populateDb() + throws Exception + { + Date whenGathered = Calendar.getInstance().getTime(); + whenGathered.setTime( 123456789 ); + + ArchivaArtifact artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0" ); + artifact.getModel().setWhenGathered( null ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.1" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "1.0.2" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "org.apache.archiva", "artifact-one", "2.0" ); + artifact.getModel().setRepositoryId( "different-repo" ); + artifact.getModel().setWhenGathered( whenGathered ); + artifactDao.saveArtifact( artifact ); + } + + public void testQueryAllVersionsOfArtifactAcrossRepos() throws Exception + { + populateDb(); + assertConstraint( "Artifacts By Repository", 3, + new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one" ) ); + } + + public void testQueryAllVersionsOfArtifactInARepo() throws Exception + { + populateDb(); + assertConstraint( "Artifacts By Repository", 2, + new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one" ) ); + } + + private void assertConstraint( String msg, int count, ArtifactVersionsConstraint constraint ) + throws Exception + { + List results = artifactDao.queryArtifacts( constraint ); + assertNotNull( msg + ": Not Null", results ); + assertEquals( msg + ": Results.size", count, results.size() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java index 1cf82879d..3bf70827a 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java @@ -20,7 +20,6 @@ package org.apache.archiva.rss; */ import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import org.slf4j.Logger; -- 2.39.5