vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/Launchers.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 23 Dec 2012 23:30:06 +0100
branchlauncher
changeset 372 3485327d3080
parent 371 vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/Launcher.java@bafc670aa10d
child 380 4ce33ad7d507
permissions -rw-r--r--
Execution time reported by TestNG reflect the time it took to run the query inside of a browser
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@356
    21
import org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher;
jaroslav@370
    22
import org.apidesign.bck2brwsr.launcher.JSLauncher;
jaroslav@370
    23
import org.apidesign.bck2brwsr.launcher.MethodInvocation;
jaroslav@372
    24
import org.apidesign.vm4brwsr.Bck2Brwsr;
jaroslav@372
    25
import org.testng.annotations.AfterGroups;
jaroslav@372
    26
import org.testng.annotations.AfterSuite;
jaroslav@372
    27
import org.testng.annotations.BeforeGroups;
jaroslav@372
    28
import org.testng.annotations.BeforeSuite;
jaroslav@356
    29
jaroslav@356
    30
/**
jaroslav@356
    31
 *
jaroslav@356
    32
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@356
    33
 */
jaroslav@372
    34
public final class Launchers {
jaroslav@372
    35
    public static final Launchers INSTANCE = new Launchers();
jaroslav@356
    36
    
jaroslav@372
    37
    private JSLauncher jsl;
jaroslav@372
    38
    private Bck2BrwsrLauncher brwsr;
jaroslav@372
    39
    
jaroslav@372
    40
    private Launchers() {
jaroslav@356
    41
    }
jaroslav@356
    42
jaroslav@372
    43
    @BeforeGroups("run")
jaroslav@372
    44
    public void initializeLauncher() throws IOException {
jaroslav@372
    45
        jsl = new JSLauncher();
jaroslav@372
    46
        jsl.addClassLoader(Bck2Brwsr.class.getClassLoader());
jaroslav@372
    47
        jsl.initialize();
jaroslav@372
    48
        Bck2BrwsrLauncher l = new Bck2BrwsrLauncher();
jaroslav@372
    49
        l.addClassLoader(Bck2Brwsr.class.getClassLoader());
jaroslav@372
    50
        l.initialize();
jaroslav@372
    51
        l.setTimeout(180000);
jaroslav@372
    52
        brwsr = l;
jaroslav@356
    53
    }
jaroslav@356
    54
jaroslav@372
    55
    @AfterGroups("run")
jaroslav@372
    56
    public void shutDownLauncher() throws IOException, InterruptedException {
jaroslav@372
    57
        brwsr.shutdown();
jaroslav@372
    58
    }
jaroslav@372
    59
jaroslav@372
    60
    public MethodInvocation addMethod(Class<?> clazz, String name, boolean inBrwsr) throws IOException {
jaroslav@372
    61
        if (!inBrwsr) {
jaroslav@372
    62
            return jsl.addMethod(clazz, name);
jaroslav@370
    63
        } else {
jaroslav@372
    64
            return brwsr.addMethod(clazz, name);
jaroslav@370
    65
        }
jaroslav@356
    66
    }
jaroslav@356
    67
}