/*
 * Copyright 2023 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wildfly.prospero.galleon;

import org.jboss.galleon.universe.maven.MavenArtifact;
import org.jboss.galleon.universe.maven.MavenUniverseException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.wildfly.channel.ArtifactTransferException;
import org.wildfly.channel.ChannelSession;

import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ChannelMavenArtifactRepositoryManagerTest {

    @Mock
    private ChannelSession session;

    private ChannelMavenArtifactRepositoryManager repositoryManager;

    @Before
    public void setUp() throws Exception {
        repositoryManager = new ChannelMavenArtifactRepositoryManager(session);
    }

    @Test
    public void testRequireChannelResolutionWhenFeaturePackVersionIsNotSpecified() throws Exception {
        when(session.resolveMavenArtifact("foo", "bar", "zip", "", null))
                .thenThrow(ArtifactTransferException.class);


        final MavenArtifact artifact = new MavenArtifact();
        artifact.setGroupId("foo");
        artifact.setArtifactId("bar");
        // Galleon glitch
        artifact.setVersion("zip");
        artifact.setExtension("zip");
        assertThrows(MavenUniverseException.class, ()->repositoryManager.resolve(artifact));
    }
}