View Javadoc

1   package org.apache.maven.archiva.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 java.util.Date;
23  import java.util.List;
24  
25  import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
26  import org.apache.maven.archiva.model.ArchivaArtifact;
27  import org.apache.maven.archiva.repository.ManagedRepositoryContent;
28  import org.apache.maven.archiva.repository.events.RepositoryListener;
29  import org.codehaus.plexus.spring.PlexusToSpringUtils;
30  
31  public class RepositoryDatabaseEventListenerTest
32      extends AbstractArchivaDatabaseTestCase
33  {
34      private RepositoryListener listener;
35  
36      @Override
37      protected void setUp()
38          throws Exception
39      {
40          super.setUp();
41  
42          listener = (RepositoryListener) lookup( RepositoryListener.class.getName(), "database" );
43      }
44  
45      @SuppressWarnings("unchecked")
46      public void testWiring()
47      {
48          List<RepositoryListener> listeners =
49              PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( RepositoryListener.class ),
50                                              getApplicationContext() );
51  
52          assertEquals( 1, listeners.size() );
53          assertEquals( listener, listeners.get( 0 ) );
54      }
55  
56      public ArchivaArtifact createArtifact( String artifactId, String version, ArtifactDAO artifactDao )
57      {
58          ArchivaArtifact artifact =
59              artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, "", "jar", "testable_repo" );
60          artifact.getModel().setLastModified( new Date() );
61          artifact.getModel().setRepositoryId( "testable_repo" );
62          return artifact;
63      }
64  
65      public void testDeleteArtifact()
66          throws Exception
67      {
68          ArtifactDAO artifactDao = (ArtifactDAO) lookup( ArtifactDAO.class.getName(), "jdo" );
69  
70          // Setup artifacts in fresh DB.
71          ArchivaArtifact artifact = createArtifact( "test-artifact", "1.0", artifactDao );
72          artifactDao.saveArtifact( artifact );
73  
74          assertEquals( artifact, artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null,
75                                                           "jar", "testable_repo" ) );
76  
77          artifact = new ArchivaArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar", "testable_repo" );
78          ManagedRepositoryContent repository =
79              (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class.getName(), "default" );
80          ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
81          configuration.setId("testable_repo");
82          repository.setRepository(configuration);
83          
84          listener.deleteArtifact( repository, artifact );
85  
86          try
87          {
88              artifactDao.getArtifact( "org.apache.maven.archiva.test", "test-artifact", "1.0", null, "jar", "testable_repo" );
89              fail( "Should not find artifact" );
90          }
91          catch ( ObjectNotFoundException e )
92          {
93              assertTrue( true );
94          }
95      }
96  }