1 package org.apache.maven.archiva.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 java.util.Date;
23 import java.util.List;
25 import org.apache.maven.archiva.model.ArchivaArtifact;
26 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
27 import org.apache.maven.archiva.repository.events.RepositoryListener;
28 import org.codehaus.plexus.spring.PlexusToSpringUtils;
30 public class RepositoryDatabaseEventListenerTest
31 extends AbstractArchivaDatabaseTestCase
33 private RepositoryListener listener;
36 protected void setUp()
41 listener = (RepositoryListener) lookup( RepositoryListener.class.getName(), "database" );
44 public void testWiring()
46 List<RepositoryListener> listeners =
47 PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( RepositoryListener.class ),
48 getApplicationContext() );
50 assertEquals( 1, listeners.size() );
51 assertEquals( listener, listeners.get( 0 ) );
54 public ArchivaArtifact createArtifact( String artifactId, String version, ArtifactDAO artifactDao )
56 ArchivaArtifact artifact =
57 artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, "", "jar" );
58 artifact.getModel().setLastModified( new Date() );
59 artifact.getModel().setRepositoryId( "testable_repo" );
63 public void testDeleteArtifact()
66 ArtifactDAO artifactDao = (ArtifactDAO) lookup( ArtifactDAO.class.getName(), "jdo" );
68 // Setup artifacts in fresh DB.
69 ArchivaArtifact artifact = createArtifact( "test-artifact", "1.0", artifactDao );
70 artifactDao.saveArtifact( artifact );
72 assertEquals( artifact, artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null,
75 artifact = new ArchivaArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar" );
76 ManagedRepositoryContent repository =
77 (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class.getName(), "default" );
78 listener.deleteArtifact( repository, artifact );
82 artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar" );
83 fail( "Should not find artifact" );
85 catch ( ObjectNotFoundException e )