View Javadoc

1   package org.apache.maven.archiva.consumers.database;
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.easymock.MockControl;
23  import org.apache.maven.archiva.model.ArchivaArtifact;
24  import org.apache.maven.archiva.database.ArtifactDAO;
25  import org.apache.maven.archiva.database.RepositoryProblemDAO;
26  
27  /**
28   * Test for DatabaseCleanupRemoveArtifactConsumerTest
29   * 
30   */
31  public class DatabaseCleanupRemoveArtifactConsumerTest
32      extends AbstractDatabaseCleanupTest
33  {
34      private MockControl artifactDAOControl;
35  
36      private ArtifactDAO artifactDAOMock;
37  
38      private MockControl repositoryProblemDAOControl;
39  
40      private RepositoryProblemDAO repositoryProblemDAOMock;
41  
42      private DatabaseCleanupRemoveArtifactConsumer dbCleanupRemoveArtifactConsumer;
43  
44      public void setUp()
45          throws Exception
46      {
47          super.setUp();
48  
49          dbCleanupRemoveArtifactConsumer = new DatabaseCleanupRemoveArtifactConsumer();
50  
51          artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
52  
53          artifactDAOMock = (ArtifactDAO) artifactDAOControl.getMock();
54  
55          repositoryProblemDAOControl = MockControl.createControl( RepositoryProblemDAO.class );
56  
57          repositoryProblemDAOMock = (RepositoryProblemDAO) repositoryProblemDAOControl.getMock();
58  
59          dbCleanupRemoveArtifactConsumer.setArtifactDAO( artifactDAOMock );
60  
61          dbCleanupRemoveArtifactConsumer.setRepositoryProblemDAO( repositoryProblemDAOMock );
62  
63          dbCleanupRemoveArtifactConsumer.setRepositoryFactory( repositoryFactory );
64      }
65  
66      public void testIfArtifactWasNotDeleted()
67          throws Exception
68      {
69          ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
70  
71          artifactDAOControl.replay();
72  
73          repositoryProblemDAOControl.replay();
74  
75          dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
76  
77          artifactDAOControl.verify();
78          
79          repositoryProblemDAOControl.verify();
80      }
81  
82      public void testIfArtifactWasDeleted()
83          throws Exception
84      {
85          ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "jar" );
86  
87          artifactDAOMock.deleteArtifact( artifact );
88  
89          artifactDAOControl.replay();
90          
91          dbCleanupRemoveArtifactConsumer.processArchivaArtifact( artifact );
92  
93          artifactDAOControl.verify();        
94      }
95  
96  }