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.setRepositoryFactory( repositoryFactory );
57 public void testIfArtifactWasNotDeleted()
60 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "pom" );
62 projectModelDAOControl.replay();
64 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
66 projectModelDAOControl.verify();
69 public void testIfArtifactWasDeleted()
72 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "pom" );
74 ArchivaProjectModel projectModel = createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
76 //this should return a value
77 projectModelDAOControl.expectAndReturn(
78 projectModelDAOMock.getProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
79 (ArchivaProjectModel) projectModel );
81 projectModelDAOMock.deleteProjectModel( projectModel );
83 projectModelDAOControl.replay();
85 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
87 projectModelDAOControl.verify();
90 public void testIfArtifactWasNotAPom()
93 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
95 projectModelDAOControl.replay();
97 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
99 projectModelDAOControl.verify();
102 public void tearDown()