/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This 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 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.as.test.surefire.servermodule;

import java.util.Collections;
import java.util.Properties;

import junit.framework.Assert;

import org.jboss.as.server.Bootstrap;
import org.jboss.as.server.Main;
import org.jboss.as.server.ServerController;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceActivator;
import org.junit.Test;

/**
 * Here to prove the forked surefire plugin is capable of running
 * modular tests. This plugin will load up this test class in a module that can see
 * org.jboss.as.standalone.
 *
 * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
 * @version $Revision: 1.1 $
 */
public class ServerInModuleStartupTestCase {

    @Test
    public void testServerStartupAndShutDown() throws Exception {
        System.out.println(Main.class.getClassLoader());
        ServerEnvironment serverEnvironment = Main.determineEnvironment(new String[0], new Properties(System.getProperties()), System.getenv());
        Assert.assertNotNull(serverEnvironment);
        final Bootstrap bootstrap = Bootstrap.Factory.newInstance();
        final Bootstrap.Configuration configuration = new Bootstrap.Configuration();
        configuration.setServerEnvironment(serverEnvironment);
        configuration.setModuleLoader(Module.getSystemModuleLoader());
        configuration.setPortOffset(0);

        final ServerController controller = bootstrap.start(configuration, Collections.<ServiceActivator>emptyList()).get();
        Assert.assertNotNull(controller);
        controller.shutdown();
        controller.awaitTermination();
        Assert.assertTrue(controller.isShutdownComplete());
    }
}

@@ -1162,46 +1162,8 @@
 t;%0A%0A
-import org.jboss.as.server.Bootstrap;%0A
 impo
@@ -1218,32 +1218,28 @@
 .server.
-ServerController
+NewBootstrap
 ;%0Aimport
@@ -1358,16 +1358,63 @@
 ivator;%0A
+import org.jboss.msc.service.ServiceContainer;%0A
 import o
@@ -2083,32 +2083,35 @@
 ;%0A        final 
+New
 Bootstrap bootst
@@ -2116,16 +2116,19 @@
 strap = 
+New
 Bootstra
@@ -2166,16 +2166,19 @@
   final 
+New
 Bootstra
@@ -2213,16 +2213,19 @@
 n = new 
+New
 Bootstra
@@ -2440,29 +2440,28 @@
 Serv
+ic
 e
-r
 Cont
-roll
+ain
 er cont
-roll
+ain
 er =
@@ -2575,20 +2575,19 @@
 ull(cont
-roll
+ain
 er);%0A   
@@ -2595,20 +2595,19 @@
     cont
-roll
+ain
 er.shutd
@@ -2625,20 +2625,19 @@
     cont
-roll
+ain
 er.await
@@ -2685,12 +2685,11 @@
 cont
-roll
+ain
 er.i
@@ -2706,20 +2706,23 @@
 omplete());%0A
+%0A%0A%0A
     %7D%0A%7D%0A

Update ServerInModuleStartupTestCase to use the new bootstrap