package org.apache.maven.simian;

/* ====================================================================
 *   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 java.io.*;

import org.apache.commons.jelly.JellyContext;

/**
 *
 * @author Aslak Hellesoy
 * @version $Revision: 1.2 $
 */
public class SimianLogTest extends TestCase {
    public void testGetDuplications() throws IOException {
        SimianLog simianLog = new SimianLog();

        File logFile = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "target/simian-test/simian.log" );
        simianLog.setLogFile(logFile);

        JellyContext ctx = new JellyContext();
        simianLog.setJellyContext(ctx);

        String sourceDirectory = new File(FileUtils.getRoot(getClass()).getParentFile().getParentFile(), "src/test" ).getAbsolutePath();
        simianLog.setSourceDirectory(sourceDirectory);

        simianLog.process();

        Duplication[] duplications = simianLog.getDuplications();
        assertEquals("There should be 1 duplication", 1, duplications.length );

        Duplication duplication = duplications[0];

        DuplicationArea[] duplicationAreas = duplication.getDuplicationAreas();
        assertEquals("There should be 2 duplicated areas", 2, duplicationAreas.length );

        String pathToClass = duplicationAreas[0].getPathToClass();
        assertTrue( "The pathToClass should start with xref/org/apache/maven/simian, but was " + pathToClass,
                pathToClass.startsWith("xref/org/apache/maven/simian") );

        assertSame("The SimianLog should be on the Jelly Context", simianLog, ctx.getVariable("simianLog") );
    }
}
