1 package org.apache.maven.archiva.consumers.database;
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.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;
28 * Test for DatabaseCleanupRemoveProjectConsumer
30 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
32 public class DatabaseCleanupRemoveProjectConsumerTest
33 extends AbstractDatabaseCleanupTest
35 private MockControl projectModelDAOControl;
37 private ProjectModelDAO projectModelDAOMock;
39 private DatabaseCleanupRemoveProjectConsumer dbCleanupRemoveProjectConsumer;
46 dbCleanupRemoveProjectConsumer = new DatabaseCleanupRemoveProjectConsumer();
48 projectModelDAOControl = MockControl.createControl( ProjectModelDAO.class );
50 projectModelDAOMock = (ProjectModelDAO) projectModelDAOControl.getMock();
52 dbCleanupRemoveProjectConsumer.setProjectModelDAO( projectModelDAOMock );
54 dbCleanupRemoveProjectConsumer.setBidirectionalRepositoryLayoutFactory( layoutFactory );
56 dbCleanupRemoveProjectConsumer.setRepositoryFactory( repositoryFactory );
59 public void testIfArtifactWasNotDeleted()
62 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "pom" );
64 projectModelDAOControl.replay();
66 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
68 projectModelDAOControl.verify();
71 public void testIfArtifactWasDeleted()
74 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "pom" );
76 ArchivaProjectModel projectModel = createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
78 //this should return a value
79 projectModelDAOControl.expectAndReturn(
80 projectModelDAOMock.getProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
81 (ArchivaProjectModel) projectModel );
83 projectModelDAOMock.deleteProjectModel( projectModel );
85 projectModelDAOControl.replay();
87 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
89 projectModelDAOControl.verify();
92 public void testIfArtifactWasNotAPom()
95 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
97 projectModelDAOControl.replay();
99 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
101 projectModelDAOControl.verify();
104 public void tearDown()