vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 25 Dec 2012 15:31:58 +0100
changeset 383 88ed1f51eb22
parent 382 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java@57fc3a0563c9
child 384 269d99fd6421
permissions -rw-r--r--
One can specify list of browsers to test in via 'vmtest.brwsrs' property
jaroslav@356
     1
/**
jaroslav@356
     2
 * Back 2 Browser Bytecode Translator
jaroslav@356
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@356
     4
 *
jaroslav@356
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@356
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@356
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@356
     8
 *
jaroslav@356
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@356
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@356
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@356
    12
 * GNU General Public License for more details.
jaroslav@356
    13
 *
jaroslav@356
    14
 * You should have received a copy of the GNU General Public License
jaroslav@356
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@356
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@356
    17
 */
jaroslav@372
    18
package org.apidesign.bck2brwsr.vmtest.impl;
jaroslav@356
    19
jaroslav@370
    20
import java.io.IOException;
jaroslav@383
    21
import java.util.LinkedHashMap;
jaroslav@383
    22
import java.util.Map;
jaroslav@382
    23
import org.apidesign.bck2brwsr.launcher.Launcher;
jaroslav@370
    24
import org.apidesign.bck2brwsr.launcher.MethodInvocation;
jaroslav@372
    25
import org.testng.annotations.AfterGroups;
jaroslav@372
    26
import org.testng.annotations.BeforeGroups;
jaroslav@356
    27
jaroslav@356
    28
/**
jaroslav@356
    29
 *
jaroslav@356
    30
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@356
    31
 */
jaroslav@383
    32
public final class LaunchSetup {
jaroslav@383
    33
    private static final LaunchSetup JS = new LaunchSetup(Launcher.createJavaScript());
jaroslav@383
    34
    private static final Map<String,LaunchSetup> BRWSRS = new LinkedHashMap<>();
jaroslav@356
    35
    
jaroslav@383
    36
    private final Launcher launcher;
jaroslav@372
    37
    
jaroslav@383
    38
    private LaunchSetup(Launcher l) {
jaroslav@383
    39
        launcher = l;
jaroslav@383
    40
    }
jaroslav@383
    41
    
jaroslav@383
    42
    public static LaunchSetup javaScript() {
jaroslav@383
    43
        return JS;
jaroslav@383
    44
    } 
jaroslav@383
    45
    
jaroslav@383
    46
    public static synchronized LaunchSetup brwsr(String cmd) {
jaroslav@383
    47
        LaunchSetup s = BRWSRS.get(cmd);
jaroslav@383
    48
        if (s == null) {
jaroslav@383
    49
            s = new LaunchSetup(Launcher.createBrowser(cmd));
jaroslav@383
    50
            BRWSRS.put(cmd, s);
jaroslav@383
    51
        }
jaroslav@383
    52
        return s;
jaroslav@356
    53
    }
jaroslav@356
    54
jaroslav@372
    55
    @BeforeGroups("run")
jaroslav@372
    56
    public void initializeLauncher() throws IOException {
jaroslav@383
    57
        launcher.initialize();
jaroslav@356
    58
    }
jaroslav@356
    59
jaroslav@372
    60
    @AfterGroups("run")
jaroslav@372
    61
    public void shutDownLauncher() throws IOException, InterruptedException {
jaroslav@383
    62
        launcher.shutdown();
jaroslav@372
    63
    }
jaroslav@372
    64
jaroslav@383
    65
    public MethodInvocation invokeMethod(Class<?> clazz, String name) throws IOException {
jaroslav@383
    66
        return launcher.invokeMethod(clazz, name);
jaroslav@356
    67
    }
jaroslav@356
    68
}