/**
* Copyright (C) 2008-2010, Squale Project - http://www.squale.org
*
* This file is part of Squale.
*
* Squale is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* Squale is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Squale. If not, see <http://www.gnu.org/licenses/>.
*/
package org.squale.squalix.tools.cpd;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.squale.squalecommon.SqualeTestCase;
import org.squale.squalecommon.daolayer.component.ProjectDAOImpl;
import org.squale.squalecommon.daolayer.component.ProjectParameterDAOImpl;
import org.squale.squalecommon.enterpriselayer.businessobject.component.ApplicationBO;
import org.squale.squalecommon.enterpriselayer.businessobject.component.AuditBO;
import org.squale.squalecommon.enterpriselayer.businessobject.component.ProjectBO;
import org.squale.squalecommon.enterpriselayer.businessobject.component.parameters.ListParameterBO;
import org.squale.squalecommon.enterpriselayer.businessobject.component.parameters.MapParameterBO;
import org.squale.squalecommon.enterpriselayer.businessobject.component.parameters.ParametersConstants;
import org.squale.squalecommon.enterpriselayer.businessobject.component.parameters.StringParameterBO;
import org.squale.squalecommon.enterpriselayer.businessobject.rule.QualityGridBO;
import org.squale.squalix.core.TaskData;
/**
* Test du processing JavaCpd
*/
public class JavaCpdProcessingTest
extends SqualeTestCase
{
/** r�pertoire des .java */
public static final String SOURCES_DIR = "data/Project4CpdTest";
/**
* Pseudo-chemin vers une vue.
*/
private static final String VIEW_PATH = ".";
/** l'application */
private ApplicationBO mAppli = new ApplicationBO();
/** le projet � auditer */
private ProjectBO mProject = new ProjectBO();
/** l'audit */
private AuditBO mAudit = new AuditBO();
/** les t�ches temporaires */
private TaskData mData = new TaskData();
/**
* @see TestCase#setUp()
*/
protected void setUp()
throws Exception
{
super.setUp();
getSession().beginTransaction();
mAppli = getComponentFactory().createApplication( getSession() );
QualityGridBO grid = getComponentFactory().createGrid( getSession() );
mProject = getComponentFactory().createProject( getSession(), mAppli, grid );
// Enregistrement du ProjectBO dans la base
ProjectDAOImpl projectDAO = ProjectDAOImpl.getInstance();
// Les param�tres doivent contenir le chemin du fichier de configuration
MapParameterBO params = new MapParameterBO();
ListParameterBO listParam = new ListParameterBO();
List list = new ArrayList();
StringParameterBO stringParam = new StringParameterBO();
stringParam.setValue( SOURCES_DIR );
list.add( stringParam );
listParam.setParameters( list );
params.getParameters().put( ParametersConstants.SOURCES, listParam );
// Pas de r�pertoire exclu
ProjectParameterDAOImpl.getInstance().create( getSession(), params );
mProject.setParameters( params );
ProjectDAOImpl.getInstance().save( getSession(), mProject );
mAudit = getComponentFactory().createAudit( this.getSession(), mProject );
// On fait le commit pour permettre l'acc�s aux donn�es dans une autre session
getSession().commitTransactionWithoutClose();
File viewFile = new File( VIEW_PATH );
mData.putData( TaskData.VIEW_PATH, viewFile.getCanonicalPath() );
}
/**
* Test d'ex�cution
*/
public void testExecute()
{
try
{
JavaCpdProcessing processing = new JavaCpdProcessing();
Iterator det = processing.process( mData, mProject.getParameters() );
int count = 0;
while ( det.hasNext() )
{
count++;
det.next();
}
final int cpCount = 7;
assertEquals( cpCount, count );
}
catch ( Exception e )
{
e.printStackTrace();
fail( "unexpected exception" );
}
}
}