View Javadoc

1   package org.apache.maven.archiva.database.updater;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
23  import org.apache.maven.archiva.database.ArtifactDAO;
24  import org.apache.maven.archiva.model.ArchivaArtifact;
25  
26  import java.util.Date;
27  
28  /**
29   * DatabaseUpdaterTest 
30   *
31   * @version $Id: DatabaseUpdaterTest.java 742859 2009-02-10 05:35:05Z jdumay $
32   */
33  public class DatabaseUpdaterTest
34      extends AbstractArchivaDatabaseTestCase
35  {
36      private DatabaseUpdater dbupdater;
37  
38      public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String whenProcessed )
39          throws Exception
40      {
41          ArchivaArtifact artifact = dao.getArtifactDAO().createArtifact( groupId, artifactId, version, "", "jar", "testrepo" );
42          assertNotNull( "Artifact should not be null.", artifact );
43          Date dateWhenProcessed = null;
44  
45          if ( whenProcessed != null )
46          {
47              dateWhenProcessed = toDate( whenProcessed );
48          }
49  
50          artifact.getModel().setWhenProcessed( dateWhenProcessed );
51  
52          // Satisfy table / column requirements.
53          artifact.getModel().setLastModified( new Date() );
54  
55          return artifact;
56      }
57  
58      @Override
59      protected void setUp()
60          throws Exception
61      {
62          super.setUp();
63  
64          ArtifactDAO adao = dao.getArtifactDAO();
65          assertNotNull( "Artifact DAO should not be null.", adao );
66  
67          adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-common", "1.0-SNAPSHOT", null ) );
68          adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-utils", "1.0-SNAPSHOT", null ) );
69          adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-old", "0.1", "2004/02/15 9:01:00" ) );
70          adao.saveArtifact( createArtifact( "org.apache.maven.archiva", "archiva-database", "1.0-SNAPSHOT", null ) );
71  
72          dbupdater = (DatabaseUpdater) lookup( DatabaseUpdater.class, "jdo" );
73          assertNotNull( "DatabaseUpdater should not be null.", dbupdater );
74      }
75  
76      public void testUpdateUnprocessed()
77          throws Exception
78      {
79          String groupId = "org.apache.maven.archiva";
80          String artifactId = "archiva-utils";
81          String version = "1.0-SNAPSHOT";
82          String classifier = "";
83          String type = "jar";
84          
85          TestDatabaseUnprocessedConsumer consumer = lookupTestUnprocessedConsumer();
86          consumer.resetCount();
87  
88          // Check the state of the artifact in the DB.
89          ArchivaArtifact savedArtifact = dao.getArtifactDAO().getArtifact( groupId, artifactId, version, classifier,
90                                                                            type, "testrepo" );
91          assertFalse( "Artifact should not be considered processed (yet).", savedArtifact.getModel().isProcessed() );
92  
93          // Update the artifact
94          dbupdater.updateUnprocessed( savedArtifact );
95  
96          // Check the update.
97          ArchivaArtifact processed = dao.getArtifactDAO().getArtifact( groupId, artifactId, version, classifier, type, "testrepo" );
98          assertTrue( "Artifact should be flagged as processed.", processed.getModel().isProcessed() );
99  
100         // Did the unprocessed consumer do it's thing?
101         assertEquals( "Processed Count.", 1, consumer.getCountProcessed() );
102     }
103 }