package org.apache.maven.dist;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   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.
 * ====================================================================
 */

import org.apache.maven.MavenException;
import org.apache.maven.project.Project;
import org.apache.maven.repository.ArtifactTypeHandler;

import junit.framework.TestCase;

/**
 *  This will do until wagon debuts.
 * 
 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 
 * @version $Id$
 */
public class DistributionArtifactTypeHandlerTest extends TestCase
{
    private Project project;
    private ArtifactTypeHandler handler;
    private static final String VERSION = "VERSION";

    public void setUp() throws Exception
    {
        project = new Project();
        project.setGroupId("groupId");
        project.setArtifactId("artifactId");
        handler = new DistributionArtifactTypeHandler();
    }

    public void testConstructRepositoryDirectoryPath() throws Exception
    {
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-targz", project));
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-tarbz2", project));
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-zip", project));
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-src-targz", project));
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-src-tarbz2", project));
        assertEquals("check artifact directory", "groupId/distributions/", 
            handler.constructRepositoryDirectoryPath("distribution-src-zip", project));
    }

    public void testConstructRepositoryFullPath() throws Exception
    {
        try {
            handler.constructRepositoryFullPath("foo", project, VERSION);
            fail("expected exception");
        }
        catch (MavenException expected) {
            assertTrue("expected exception", true);
        }

        try {
            handler.constructRepositoryFullPath("distribution", project, VERSION);
            fail("expected exception");
        }
        catch (MavenException expected) {
            assertTrue("expected exception", true);
        }

        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.tar.gz", 
            handler.constructRepositoryFullPath("distribution-targz", project, VERSION));
        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.tar.bz2", 
            handler.constructRepositoryFullPath("distribution-tarbz2", project, VERSION));
        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.zip",
            handler.constructRepositoryFullPath("distribution-zip", project, VERSION));
        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.tar.gz", 
            handler.constructRepositoryFullPath("distribution-src-targz", project, VERSION));
        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.tar.bz2", 
            handler.constructRepositoryFullPath("distribution-src-tarbz2", project, VERSION));
        assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.zip",
            handler.constructRepositoryFullPath("distribution-src-zip", project, VERSION));
    }
}

