jaroslav@356: /** jaroslav@356: * Back 2 Browser Bytecode Translator jaroslav@356: * Copyright (C) 2012 Jaroslav Tulach jaroslav@356: * jaroslav@356: * This program is free software: you can redistribute it and/or modify jaroslav@356: * it under the terms of the GNU General Public License as published by jaroslav@356: * the Free Software Foundation, version 2 of the License. jaroslav@356: * jaroslav@356: * This program is distributed in the hope that it will be useful, jaroslav@356: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@356: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@356: * GNU General Public License for more details. jaroslav@356: * jaroslav@356: * You should have received a copy of the GNU General Public License jaroslav@356: * along with this program. Look for COPYING file in the top folder. jaroslav@356: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@356: */ jaroslav@372: package org.apidesign.bck2brwsr.vmtest.impl; jaroslav@356: jaroslav@370: import java.io.IOException; jaroslav@383: import java.util.LinkedHashMap; jaroslav@383: import java.util.Map; jaroslav@382: import org.apidesign.bck2brwsr.launcher.Launcher; jaroslav@370: import org.apidesign.bck2brwsr.launcher.MethodInvocation; jaroslav@372: import org.testng.annotations.AfterGroups; jaroslav@372: import org.testng.annotations.BeforeGroups; jaroslav@356: jaroslav@356: /** jaroslav@356: * jaroslav@356: * @author Jaroslav Tulach jaroslav@356: */ jaroslav@383: public final class LaunchSetup { jaroslav@383: private static final LaunchSetup JS = new LaunchSetup(Launcher.createJavaScript()); jaroslav@383: private static final Map BRWSRS = new LinkedHashMap<>(); jaroslav@356: jaroslav@383: private final Launcher launcher; jaroslav@372: jaroslav@383: private LaunchSetup(Launcher l) { jaroslav@383: launcher = l; jaroslav@383: } jaroslav@383: jaroslav@383: public static LaunchSetup javaScript() { jaroslav@383: return JS; jaroslav@383: } jaroslav@383: jaroslav@383: public static synchronized LaunchSetup brwsr(String cmd) { jaroslav@383: LaunchSetup s = BRWSRS.get(cmd); jaroslav@383: if (s == null) { jaroslav@383: s = new LaunchSetup(Launcher.createBrowser(cmd)); jaroslav@383: BRWSRS.put(cmd, s); jaroslav@383: } jaroslav@383: return s; jaroslav@356: } jaroslav@356: jaroslav@372: @BeforeGroups("run") jaroslav@372: public void initializeLauncher() throws IOException { jaroslav@383: launcher.initialize(); jaroslav@356: } jaroslav@356: jaroslav@372: @AfterGroups("run") jaroslav@372: public void shutDownLauncher() throws IOException, InterruptedException { jaroslav@383: launcher.shutdown(); jaroslav@372: } jaroslav@372: jaroslav@383: public MethodInvocation invokeMethod(Class clazz, String name) throws IOException { jaroslav@383: return launcher.invokeMethod(clazz, name); jaroslav@356: } jaroslav@356: }