package cz.muni.fi.jboss.migration;

import cz.muni.fi.jboss.migration.conf.Configuration;
import cz.muni.fi.jboss.migration.utils.AS7CliUtils;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 *
 * @author Ondrej Zizka, ozizka at redhat.com
 */
@RunWith(Arquillian.class)
public class ArqTest {
    
    private static Configuration createTestConfig01() {
        Configuration conf = new Configuration();
        
        conf.getGlobal().getAS5Config().setDir("testdata/as5configs/01_510all");
        conf.getGlobal().getAS5Config().setProfileName("all");
        
        conf.getGlobal().getAS7Config().setDir("target/jboss-as-7.1.1.Final");
        conf.getGlobal().getAS7Config().setConfigPath("standalone/configuration/standalone.xml");
                
        return conf;
    }
    

    
    /**
     * Test of doMigration method, of class MigratorEngine.
     */
    @Test
    @RunAsClient
    public void testDoMigration( @ArquillianResource ManagementClient client ) throws Exception {
        System.out.println( "doMigration" );
                
        Configuration conf = createTestConfig01();
        
        // Set the Mgmt host & port from the client;
        conf.getGlobal().getAS7Config().setHost( client.getMgmtAddress() );
        conf.getGlobal().getAS7Config().setManagementPort( client.getMgmtPort() );
        
        // Then query for the server path.
        String as7Dir = AS7CliUtils.queryServerHomeDir(client.getControllerClient() );
        conf.getGlobal().getAS7Config().setDir( as7Dir );
        
        MigratorApp.validateConfiguration( conf );
        
        //MigratorApp.migrate( conf );
        MigratorEngine migrator = new MigratorEngine(conf);
        migrator.doMigration();
    }
    
}// class

@@ -30,16 +30,66 @@
 ation;%0A%0A
+import cz.muni.fi.jboss.migration.conf.AS7Config;%0A
 import c
@@ -401,32 +401,93 @@
 nagementClient;%0A
+import org.jboss.as.controller.client.ModelControllerClient;%0A
 import org.junit
@@ -1275,16 +1275,18 @@
 ration( 
+/*
 @Arquill
@@ -1320,16 +1320,18 @@
 t client
+*/
  ) throw
@@ -1453,24 +1453,87 @@
 Config01();%0A
+        AS7Config as7Config = conf.getGlobal().getAS7Config();%0A
         %0A   
@@ -1594,46 +1594,92 @@
     
-conf.getGlobal().getAS
+//as7Config.setHost( client.getMgmtAddress() );%0A        //as
 7Config
-()
 .set
-Hos
+ManagementPor
 t( c
@@ -1683,39 +1683,36 @@
 ( client.getMgmt
-Address
+Port
 () );%0A        co
@@ -1713,80 +1713,861 @@
     
-conf.getGlobal().getAS7Config().setManagementPort( client.getMgm
+%0A        %0A        /*%0A           This fails for some reason:%0A%0A            java.lang.RuntimeException: Provider for type class org.jboss.as.arquillian.container.ManagementClient returned a null value: org.jboss.as.arquillian.container.ManagementClientProvider@4aee4b87%0A                at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.lookup(ArquillianResourceTestEnricher.java:115)%0A                at org.jboss.arquillian.test.impl.enricher.resource.ArquillianResourceTestEnricher.resolve(ArquillianResourceTestEnricher.java:91)        %0A                 %0A           Let's resort to default values.%0A        */%0A        %0A        //ModelControllerClient as7client = client.getControllerClient();%0A        ModelControllerClient as7client = ModelControllerClient.Factory.create(as7Config.getHost(), as7Config.getManagemen
 tPort()
- 
 );%0A 
@@ -2676,36 +2676,18 @@
 Dir(
+ as7
 client
-.getControllerClient()
  );%0A

Set the Mgmt host & port from the client; Then query for the server path. @ArqResource didn't work