package org.jboss.loom.migrators._ext;

import java.io.File;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.jboss.loom.conf.GlobalConfiguration;
import org.jboss.loom.utils.Utils;
import org.junit.Test;

/**
 *
 * @author Ondrej Zizka, ozizka at redhat.com
 */
public class ExternalMigratorsLoaderTest {
    
    public ExternalMigratorsLoaderTest() {
    }


    @Test
    public void testLoadMigrators() throws Exception {
        System.out.println( "loadMigrators" );
        
        File workDir = new File("target/extMigrators/");
        FileUtils.forceMkdir( workDir );
        Utils.copyResourceToDir( ExternalMigratorsLoader.class, "TestMigrator.mig.xml", workDir );
        Utils.copyResourceToDir( ExternalMigratorsLoader.class, "TestJaxbBean.groovy",  workDir );
        
        Map<Class<? extends DefinitionBasedMigrator>, DefinitionBasedMigrator> migs
                = new ExternalMigratorsLoader().loadMigrators( workDir, new GlobalConfiguration() );
        
        for( Map.Entry<Class<? extends DefinitionBasedMigrator>, DefinitionBasedMigrator> entry : migs.entrySet() ) {
            Class<? extends DefinitionBasedMigrator> cls = entry.getKey();
            DefinitionBasedMigrator mig = entry.getValue();
            System.out.println( String.format("  Loaded migrator %s: %s", cls.getName(), mig.toString() ) );
        }
    }


}// class
@@ -54,16 +54,44 @@
 o.File;%0A
+import java.io.IOException;%0A
 import j
@@ -223,24 +223,83 @@
 tils.Utils;%0A
+import org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0A
 import org.j
@@ -424,53 +424,555 @@
    p
-ublic ExternalMigratorsLoaderTest() %7B
+rivate File workDir;%0A    %0A    @BeforeClass%0A    private void copyTestExtMigratorFiles() throws IOException %7B%0A        this.workDir = new File(%22target/extMigrators/%22);%0A        FileUtils.forceMkdir( workDir );%0A        Utils.copyResourceToDir( ExternalMigratorsLoader.class, %22TestMigrator.mig.xml%22, workDir );%0A        Utils.copyResourceToDir( ExternalMigratorsLoader.class, %22TestJaxbBean.groovy%22,  workDir );%0A    %7D%0A    %0A    @AfterClass%0A    private void deleteTestExtMigratorFiles() throws IOException %7B%0A        FileUtils.forceDelete( workDir );
 %0A    %7D%0A%0A
 %0A   
@@ -967,17 +967,16 @@
 %0A    %7D%0A%0A
-%0A
     @Tes
@@ -1092,313 +1092,8 @@
    %0A
-        File workDir = new File(%22target/extMigrators/%22);%0A        FileUtils.forceMkdir( workDir );%0A        Utils.copyResourceToDir( ExternalMigratorsLoader.class, %22TestMigrator.mig.xml%22, workDir );%0A        Utils.copyResourceToDir( ExternalMigratorsLoader.class, %22TestJaxbBean.groovy%22,  workDir );%0A        %0A
     
@@ -1235,16 +1235,21 @@
 rators( 
+this.
 workDir,
@@ -1666,17 +1666,16 @@
 %0A    %7D%0A%0A
-%0A
 %7D// clas

Improve ext mig test