View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.internal;
20  
21  import java.lang.reflect.Field;
22  
23  import org.eclipse.aether.RepositoryEvent;
24  import org.eclipse.aether.RepositoryEvent.EventType;
25  import org.eclipse.aether.artifact.DefaultArtifact;
26  import org.eclipse.aether.impl.ArtifactDescriptorReader;
27  import org.eclipse.aether.impl.RepositoryEventDispatcher;
28  import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
29  import org.junit.jupiter.api.Test;
30  import org.mockito.ArgumentCaptor;
31  
32  import static org.junit.jupiter.api.Assertions.assertEquals;
33  import static org.junit.jupiter.api.Assertions.assertTrue;
34  import static org.mockito.Mockito.mock;
35  import static org.mockito.Mockito.verify;
36  
37  class DefaultArtifactDescriptorReaderTest extends AbstractRepositoryTestCase {
38  
39      @Test
40      void testMng5459() throws Exception {
41          // prepare
42          DefaultArtifactDescriptorReader reader =
43                  (DefaultArtifactDescriptorReader) getContainer().lookup(ArtifactDescriptorReader.class);
44  
45          RepositoryEventDispatcher eventDispatcher = mock(RepositoryEventDispatcher.class);
46  
47          ArgumentCaptor<RepositoryEvent> event = ArgumentCaptor.forClass(RepositoryEvent.class);
48  
49          Field field = DefaultArtifactDescriptorReader.class.getDeclaredField("repositoryEventDispatcher");
50          field.setAccessible(true);
51          field.set(reader, eventDispatcher);
52  
53          ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
54  
55          request.addRepository(newTestRepository());
56  
57          request.setArtifact(new DefaultArtifact("org.apache.maven.its", "dep-mng5459", "jar", "0.4.0-SNAPSHOT"));
58  
59          // execute
60          reader.readArtifactDescriptor(session, request);
61  
62          // verify
63          verify(eventDispatcher).dispatch(event.capture());
64  
65          boolean missingArtifactDescriptor = false;
66  
67          for (RepositoryEvent evt : event.getAllValues()) {
68              if (EventType.ARTIFACT_DESCRIPTOR_MISSING.equals(evt.getType())) {
69                  assertEquals(
70                          "Could not find artifact org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2 in repo ("
71                                  + newTestRepository().getUrl() + ")",
72                          evt.getException().getMessage());
73                  missingArtifactDescriptor = true;
74              }
75          }
76  
77          assertTrue(
78                  missingArtifactDescriptor,
79                  "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2");
80      }
81  }