vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 25 Dec 2012 15:08:39 +0100
changeset 382 57fc3a0563c9
parent 380 4ce33ad7d507
permissions -rw-r--r--
Hidding the launchers behind common fasade
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@382
    21
import org.apidesign.bck2brwsr.launcher.Launcher;
jaroslav@370
    22
import org.apidesign.bck2brwsr.launcher.MethodInvocation;
jaroslav@372
    23
import org.testng.annotations.AfterGroups;
jaroslav@372
    24
import org.testng.annotations.BeforeGroups;
jaroslav@356
    25
jaroslav@356
    26
/**
jaroslav@356
    27
 *
jaroslav@356
    28
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@356
    29
 */
jaroslav@372
    30
public final class Launchers {
jaroslav@372
    31
    public static final Launchers INSTANCE = new Launchers();
jaroslav@356
    32
    
jaroslav@382
    33
    private Launcher jsl;
jaroslav@382
    34
    private Launcher brwsr;
jaroslav@372
    35
    
jaroslav@372
    36
    private Launchers() {
jaroslav@356
    37
    }
jaroslav@356
    38
jaroslav@372
    39
    @BeforeGroups("run")
jaroslav@372
    40
    public void initializeLauncher() throws IOException {
jaroslav@382
    41
        jsl = Launcher.createJavaScript();
jaroslav@372
    42
        jsl.initialize();
jaroslav@382
    43
        Launcher l = Launcher.createBrowser("xdg-open");
jaroslav@372
    44
        l.initialize();
jaroslav@372
    45
        brwsr = l;
jaroslav@356
    46
    }
jaroslav@356
    47
jaroslav@372
    48
    @AfterGroups("run")
jaroslav@372
    49
    public void shutDownLauncher() throws IOException, InterruptedException {
jaroslav@382
    50
        jsl.shutdown();
jaroslav@372
    51
        brwsr.shutdown();
jaroslav@372
    52
    }
jaroslav@372
    53
jaroslav@382
    54
    public MethodInvocation invokeMethod(Class<?> clazz, String name, boolean inBrwsr) throws IOException {
jaroslav@372
    55
        if (!inBrwsr) {
jaroslav@382
    56
            return jsl.invokeMethod(clazz, name);
jaroslav@370
    57
        } else {
jaroslav@382
    58
            return brwsr.invokeMethod(clazz, name);
jaroslav@370
    59
        }
jaroslav@356
    60
    }
jaroslav@356
    61
}