]> source.dussan.org Git - archiva.git/blob
646d3b0c8245881e5e8fca833c4cc1b5ec8ce459
[archiva.git] /
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.database.ProjectModelDAO;
24 import org.apache.maven.archiva.model.ArchivaArtifact;
25 import org.apache.maven.archiva.model.ArchivaProjectModel;
26
27 /**
28  * Test for DatabaseCleanupRemoveProjectConsumer
29  *
30  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
31  */
32 public class DatabaseCleanupRemoveProjectConsumerTest
33         extends AbstractDatabaseCleanupTest
34 {
35     private MockControl projectModelDAOControl;
36
37     private ProjectModelDAO projectModelDAOMock;
38
39     private DatabaseCleanupRemoveProjectConsumer dbCleanupRemoveProjectConsumer;
40
41     public void setUp()
42         throws Exception
43     {
44         super.setUp();
45
46         dbCleanupRemoveProjectConsumer = new DatabaseCleanupRemoveProjectConsumer();
47
48         projectModelDAOControl = MockControl.createControl( ProjectModelDAO.class );
49
50         projectModelDAOMock = (ProjectModelDAO) projectModelDAOControl.getMock();
51
52         dbCleanupRemoveProjectConsumer.setProjectModelDAO( projectModelDAOMock );
53         
54         dbCleanupRemoveProjectConsumer.setBidirectionalRepositoryLayoutFactory( layoutFactory );
55         
56         dbCleanupRemoveProjectConsumer.setRepositoryFactory( repositoryFactory );
57     }
58
59     public void testIfArtifactWasNotDeleted()
60         throws Exception
61     {
62         ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "pom" );
63
64         projectModelDAOControl.replay();
65
66         dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
67
68         projectModelDAOControl.verify();
69     }
70
71     public void testIfArtifactWasDeleted()
72         throws Exception
73     {
74         ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "pom" );
75
76         ArchivaProjectModel projectModel = createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
77
78         //this should return a value
79         projectModelDAOControl.expectAndReturn(
80             projectModelDAOMock.getProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
81             (ArchivaProjectModel) projectModel );
82
83         projectModelDAOMock.deleteProjectModel( projectModel );
84
85         projectModelDAOControl.replay();
86
87         dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
88
89         projectModelDAOControl.verify();
90     }
91     
92     public void testIfArtifactWasNotAPom()
93         throws Exception
94         {
95         ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
96
97         projectModelDAOControl.replay();
98
99         dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
100
101         projectModelDAOControl.verify();
102         }
103
104     public void tearDown()
105         throws Exception
106     {
107         super.tearDown();
108     }
109
110 }