View Javadoc
1   package org.apache.maven.repository.internal;
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 static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.verify;
24  
25  import org.eclipse.aether.RepositoryEvent;
26  import org.eclipse.aether.RepositoryEvent.EventType;
27  import org.eclipse.aether.artifact.DefaultArtifact;
28  import org.eclipse.aether.impl.ArtifactDescriptorReader;
29  import org.eclipse.aether.impl.RepositoryEventDispatcher;
30  import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
31  import org.mockito.ArgumentCaptor;
32  
33  public class DefaultArtifactDescriptorReaderTest
34      extends AbstractRepositoryTestCase
35  {
36  
37      public void testMng5459()
38          throws Exception
39      {
40          // prepare
41          DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) lookup( ArtifactDescriptorReader.class );
42  
43          RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class );
44  
45          ArgumentCaptor<RepositoryEvent> event = ArgumentCaptor.forClass( RepositoryEvent.class );
46  
47          reader.setRepositoryEventDispatcher( eventDispatcher );
48  
49          ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
50  
51          request.addRepository( newTestRepository() );
52  
53          request.setArtifact( new DefaultArtifact( "org.apache.maven.its", "dep-mng5459", "jar", "0.4.0-SNAPSHOT" ) );
54  
55          // execute
56          reader.readArtifactDescriptor( session, request );
57  
58          // verify
59          verify( eventDispatcher ).dispatch( event.capture() );
60  
61          boolean missingArtifactDescriptor = false;
62  
63          for( RepositoryEvent evt : event.getAllValues() )
64          {
65              if ( EventType.ARTIFACT_DESCRIPTOR_MISSING.equals( evt.getType() ) )
66              {
67                  assertEquals( "Could not find artifact org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2 in repo (" + newTestRepository().getUrl() + ")", evt.getException().getMessage() );
68                  missingArtifactDescriptor = true;
69              }
70          }
71  
72          if( !missingArtifactDescriptor )
73          {
74              fail( "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2" );
75          }
76      }
77  }