1 package org.apache.maven.archiva.database.constraints;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23 import org.apache.maven.archiva.database.ArtifactDAO;
24 import org.apache.maven.archiva.model.ArchivaArtifact;
26 import java.util.Date;
27 import java.util.Iterator;
28 import java.util.List;
31 * ArtifactsProcessedConstraintTest
35 public class ArtifactsProcessedConstraintTest
36 extends AbstractArchivaDatabaseTestCase
38 public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String whenProcessed )
41 ArchivaArtifact artifact = dao.getArtifactDAO().createArtifact( groupId, artifactId, version, "", "jar", "testrepo" );
42 assertNotNull( "Artifact should not be null.", artifact );
43 Date dateWhenProcessed = null;
45 if ( whenProcessed != null )
47 dateWhenProcessed = toDate( whenProcessed );
50 artifact.getModel().setWhenProcessed( dateWhenProcessed );
52 // Satisfy table / column requirements.
53 artifact.getModel().setLastModified( new Date() );
58 public void assertResults( String type, List results, String expectedArtifacts[] )
60 assertNotNull( "Results[" + type + "] should not be null.", results );
61 assertEquals( "Results[" + type + "].size", expectedArtifacts.length, results.size() );
63 for ( int i = 0; i < expectedArtifacts.length; i++ )
65 String artifactId = expectedArtifacts[i];
68 Iterator it = results.iterator();
69 while ( it.hasNext() )
71 ArchivaArtifact artifact = (ArchivaArtifact) it.next();
72 if ( artifactId.equals( artifact.getArtifactId() ) )
80 fail( "Results[" + type + "] - Did not find expected artifact ID [" + artifactId + "]" );
85 fail( "Results[" + type + "] - Expected to find 1 copy of artifact ID [" + artifactId
86 + "], yet found <" + found + "> instead." );
92 protected void setUp()
97 ArtifactDAO adao = dao.getArtifactDAO();
98 assertNotNull( "Artifact DAO should not be null.", adao );
100 adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-common", "1.0-SNAPSHOT", null ) );
101 adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-utils", "1.0-SNAPSHOT",
102 "2006/08/22 19:01:00" ) );
103 adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-old", "0.1", "2004/02/15 9:01:00" ) );
104 adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-database", "1.0-SNAPSHOT", null ) );
107 public void testNotProcessed()
110 List results = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( false ) );
111 assertResults( "not-processed", results, new String[] { "archiva-common", "archiva-database" } );
114 public void testProcessed()
117 List results = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( true ) );
118 assertResults( "processed", results, new String[] { "archiva-utils", "archiva-old" } );
121 public void testSinceRecent()
124 Date since = toDate( "2006/01/01 12:00:00" );
125 List results = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( since ) );
126 assertResults( "processed", results, new String[] { "archiva-utils" } );
129 public void testSinceOld()
132 Date since = toDate( "2001/01/01 12:00:00" );
133 List results = dao.getArtifactDAO().queryArtifacts( new ArtifactsProcessedConstraint( since ) );
134 assertResults( "processed", results, new String[] { "archiva-utils", "archiva-old" } );