package org.apache.maven.plugin;

/*
 * ====================================================================
 * 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 junit.framework.TestCase;
import org.jdom.JDOMException;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * @author Dion Gillard
 */
public class PluginToTagsTest extends TestCase
{
    private static final String basedir = System.getProperty("basedir");

    /**
     * test the right taglibs are found 
     * @throws JDOMException
     * @throws IOException
     */
    public void testTaglibs() throws JDOMException, IOException
    {
        PluginToTags instance = new PluginToTags();
        testBasedir();
        instance.setPluginScript(basedir + "/src/test/plugin.jelly");
        assertEquals("wrong number of taglibs", 1, instance.getTaglibs().size());
        Map taglib = (Map)instance.getTaglibs().get(0);
        assertEquals("bad taglib uri", "doc", taglib.get("uri"));
    }

    /**
     * test that basedir is passed in
     */
    public void testBasedir()
    {
        assertNotNull("no basedir", basedir);
    }

    /**
     * test the taglibs are written as a file
     * @throws JDOMException
     * @throws IOException
     */
    public void testTransform() throws JDOMException, IOException
    {
        PluginToTags instance = new PluginToTags();
        testBasedir();
        instance.setPluginScript(basedir + "/src/test/plugin.jelly");
        instance.setXdoc(basedir + "/target/tags.xml");
        instance.transform();
        File outputFile = new File(instance.getXdoc());
        assertTrue("xdoc not generated", outputFile.exists());
    }


}
