All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sitoolkit.tester.TestContext Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2013 Monocrea Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sitoolkit.tester;

import java.awt.Rectangle;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

/**
 *
 * @author yuichi.kuwahara
 */
@Component("current")
public class TestContext {

	/**
     * 現在実行中のテストスクリプトカタログ
	 */
	private TestScriptCatalog catalog;
    /**
     * 現在実行中のテストスクリプト
     */
    private TestScript testScript;
    /**
     * 現在実行中のスクリプト名
     */
    private String scriptName;
    /**
     * 現在実行中のケース番号
     */
    private String caseNo;

    /**
     * 退避用のテストスクリプトカタログ
     */
    private TestScriptCatalog catalogTmp;

    /**
     * TestContextのイベントにアタッチするためのインターフェース
     */
    private TestContextListener testContextListener;

	/**
	 * 現在実行中のテストスクリプトを指すTestScriptListのインデックス
	 */
	private int currentIndex;

	/**
	 * 退避用のインデックス
	 */
	private int indexTmp;

	/**
	 * ブラウザのウィンドウの位置とサイズを表す矩形
	 */
	private Rectangle windowRect;
    /**
     *
     */
    private Map params = new HashMap();

	public TestScriptCatalog getCatalog() {
		return catalog;
	}

	public void setCatalog(TestScriptCatalog catalog) {
		this.catalog = catalog;
	}

    public TestScript getTestScript() {
        return testScript;
    }

    public void setTestScript(TestScript testScript) {
        this.testScript = testScript;
    }

    public String getScriptName() {
        return scriptName;
    }

    public void setScriptName(String scriptName) {
        this.scriptName = scriptName;
    }

    public String getCaseNo() {
        return caseNo;
    }

    public void setCaseNo(String caseNo) {
        this.caseNo = caseNo;
    }

	public TestScriptCatalog getCatalogTmp() {
		return catalogTmp;
	}

	public void setCatalogTmp(TestScriptCatalog catalogTmp) {
		this.catalogTmp = catalogTmp;
	}

	public TestContextListener getTestContextListener() {
		return testContextListener;
	}

	public void setTestContextListener(TestContextListener testContextListener) {
		this.testContextListener = testContextListener;
	}

	public void addParam(String key, Object value) {
        params.put(key, value);
    }

    public  T getParam(String key) {
        return (T) params.get(key);
    }

	public Map getParams() {
		return params;
	}

	public void setParams(Map params) {
		this.params = params;
	}

	public boolean next() {
		if (getCurrentIndex() < getCatalog().getTestScriptCount()) {
			TestScript ts = getCatalog().getTestScript(currentIndex++);
			setTestScript(ts);
			return true;
		} else if (testContextListener != null) {
			testContextListener.onEnd(this);
			return true;
		} else {
			return false;
		}
	}

	public int getCurrentIndex() {
		return currentIndex;
	}

	public void setCurrentIndex(int currentIndex) {
		this.currentIndex = currentIndex;
	}

	public void reset() {
		setCurrentIndex(0);
	}

	public Rectangle getWindowRect() {
		return windowRect;
	}

	public void setWindowRect(Rectangle windowRect) {
		this.windowRect = windowRect;
	}

	public void setWindowRect(int x, int y, int w, int h) {
		setWindowRect(new Rectangle(x, y, w, h));
	}

	public int getIndexTmp() {
		return indexTmp;
	}

	public void setIndexTmp(int indexTmp) {
		this.indexTmp = indexTmp;
	}

	public void backup() {
		catalogTmp = catalog;
		indexTmp = currentIndex;
	}

	public void restore() {
		catalog = catalogTmp;
		currentIndex = indexTmp;
		testScript = catalog.getTestScript(currentIndex++);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy