001package org.apache.maven.repository.internal;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.mockito.Mockito.mock;
023import static org.mockito.Mockito.verify;
024
025import org.eclipse.aether.RepositoryEvent;
026import org.eclipse.aether.RepositoryEvent.EventType;
027import org.eclipse.aether.artifact.DefaultArtifact;
028import org.eclipse.aether.impl.ArtifactDescriptorReader;
029import org.eclipse.aether.impl.RepositoryEventDispatcher;
030import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
031import org.mockito.ArgumentCaptor;
032
033public class DefaultArtifactDescriptorReaderTest
034    extends AbstractRepositoryTestCase
035{
036
037    public void testMng5459()
038        throws Exception
039    {
040        // prepare
041        DefaultArtifactDescriptorReader reader = (DefaultArtifactDescriptorReader) lookup( ArtifactDescriptorReader.class );
042
043        RepositoryEventDispatcher eventDispatcher = mock( RepositoryEventDispatcher.class );
044
045        ArgumentCaptor<RepositoryEvent> event = ArgumentCaptor.forClass( RepositoryEvent.class );
046
047        reader.setRepositoryEventDispatcher( eventDispatcher );
048
049        ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
050
051        request.addRepository( newTestRepository() );
052
053        request.setArtifact( new DefaultArtifact( "org.apache.maven.its", "dep-mng5459", "jar", "0.4.0-SNAPSHOT" ) );
054
055        // execute
056        reader.readArtifactDescriptor( session, request );
057
058        // verify
059        verify( eventDispatcher ).dispatch( event.capture() );
060
061        boolean missingArtifactDescriptor = false;
062
063        for( RepositoryEvent evt : event.getAllValues() )
064        {
065            if ( EventType.ARTIFACT_DESCRIPTOR_MISSING.equals( evt.getType() ) )
066            {
067                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() );
068                missingArtifactDescriptor = true;
069            }
070        }
071
072        if( !missingArtifactDescriptor )
073        {
074            fail( "Expected missing artifact descriptor for org.apache.maven.its:dep-mng5459:pom:0.4.0-20130404.090532-2" );
075        }
076    }
077}