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.codehaus.plexus.cache.Cache;
23 import org.easymock.MockControl;
24 import org.apache.maven.archiva.database.ProjectModelDAO;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
26 import org.apache.maven.archiva.model.ArchivaProjectModel;
29 * Test for DatabaseCleanupRemoveProjectConsumer
32 public class DatabaseCleanupRemoveProjectConsumerTest
33 extends AbstractDatabaseCleanupTest
35 private MockControl projectModelDAOControl;
37 private ProjectModelDAO projectModelDAOMock;
39 private DatabaseCleanupRemoveProjectConsumer dbCleanupRemoveProjectConsumer;
41 private Cache effectiveProjectCache;
48 dbCleanupRemoveProjectConsumer = new DatabaseCleanupRemoveProjectConsumer();
50 projectModelDAOControl = MockControl.createControl( ProjectModelDAO.class );
52 projectModelDAOMock = (ProjectModelDAO) projectModelDAOControl.getMock();
54 effectiveProjectCache = (Cache) lookup( Cache.class, "effective-project-cache" );
56 dbCleanupRemoveProjectConsumer.setProjectModelDAO( projectModelDAOMock );
58 dbCleanupRemoveProjectConsumer.setRepositoryFactory( repositoryFactory );
60 dbCleanupRemoveProjectConsumer.setEffectiveProjectCache( effectiveProjectCache );
63 public void testIfArtifactWasNotDeleted()
66 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "pom" );
68 projectModelDAOControl.replay();
70 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
72 projectModelDAOControl.verify();
75 public void testIfArtifactWasDeleted()
78 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "pom" );
80 ArchivaProjectModel projectModel = createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
82 //this should return a value
83 projectModelDAOControl.expectAndReturn(
84 projectModelDAOMock.getProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
85 (ArchivaProjectModel) projectModel );
87 projectModelDAOMock.deleteProjectModel( projectModel );
89 projectModelDAOControl.replay();
91 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
93 projectModelDAOControl.verify();
96 public void testIfArtifactWasNotAPom()
99 ArchivaArtifact artifact = createArtifact( TEST_GROUP_ID, "do-not-cleanup-artifact-test", TEST_VERSION, "jar" );
101 projectModelDAOControl.replay();
103 dbCleanupRemoveProjectConsumer.processArchivaArtifact( artifact );
105 projectModelDAOControl.verify();
108 public void tearDown()