Package com.qspin.qtaste.kernel.testapi

Examples of com.qspin.qtaste.kernel.testapi.TestAPI


            if (path != null) {
                if (path.getParentPath() != null && path.getParentPath().getParentPath() != null) {
                    DefaultMutableTreeNode tn = (DefaultMutableTreeNode) path.getLastPathComponent();
                    String methodName = (String) tn.getUserObject();
                    String componentName = (String) ((DefaultMutableTreeNode) path.getParentPath().getLastPathComponent()).getUserObject();
                    TestAPI testAPI = TestAPIImpl.getInstance();
                    Method method = testAPI.getMethod(componentName, methodName);

                    String text = "testAPI.get" + componentName + "()." + methodName + "(";
                    boolean argumentAdded = false;
        if (method != null) {
                      for (Class<?> parameterType : method.getParameterTypes()) {
View Full Code Here


        // to force loading of components if not loaded
        ComponentsLoader.getInstance();

        // dynamically create VerbsTestAPI class with verbs methods
        TestAPI testAPI = TestAPIImpl.getInstance();
        Collection<String> registeredComponents = testAPI.getRegisteredComponents();

        if (engine != null) {
            Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
            if (bindings != null) {
                bindings.clear();
            }
        }

        globalBindings = engine.createBindings();
        globalBindings.put(ScriptEngine.FILENAME, "embedded_jython");
        globalBindings.put("logger", scriptLogger);
        globalBindings.put("Status", ScriptTestResultStatus.class);
        try {
            // Declare __TestAPIWrapper class, of which the testAPI variable will be an instance
            String code =
                    "import sys as __sys\n" +
                    "from sets import Set as __Set\n" +
                    "from com.qspin.qtaste.testsuite import QTasteException, QTasteTestFailException, QTasteDataException\n" +
                    "import com.qspin.qtaste.testsuite.impl.JythonTestScript.ScriptTestResultStatus as Status\n" +
                    "class ComponentNotPresentException(Exception):\n" +
                    "    pass\n" +
                    "class StepsException(Exception):\n" +
                    "    pass\n" +
                    "class ImportTestScriptException(Exception):\n" +
                    "    pass\n" +
                    "class __TestAPIWrapper:\n" +
                    "    def __init__(self, testScript):\n" +
                    "        self.testScript = testScript\n";

            code +=
                    //   new-style test api - direct method call
                    "    def __invoke(self, method, arguments):\n" +
                    "        self.testScript.logInvoke(method.im_self, method.__name__, str(arguments)[1:-1-(len(arguments)==1)])\n" +
                    "        try:\n" +
                    "            return method(*arguments)\n" +
                    "        except TypeError, e:\n" +
                    "            raise QTasteDataException('Invalid argument(s): ' + str(e))\n" +
                    "    def stopTest(self, status, message):\n" +
                    "        if status == Status.FAIL:\n" +
                    "            raise QTasteTestFailException(message)\n" +
                    "        elif status == Status.NOT_AVAILABLE:\n" +
                    "            raise QTasteDataException(message)\n" +
                    "        else:\n" +
                    "            raise SyntaxError('Invalid status argument')\n";

            // add get<Component>() methods to the __TestAPIWrapper class
            for (String component : registeredComponents) {
                code += "    def get" + component + "(self, **keywords):\n" +
                        "        component = self.testScript.getComponent('" + component + "', keywords)\n" +
                        "        return __TestAPIWrapper." + component + "Wrapper(self, component)\n";

                // declare the <Component>Wrapper class, of which the objects returned
                // by get<Component>() methods will be instances
                code += "    class " + component + "Wrapper:\n" +
                        "        def __init__(self, testAPI, component):\n" +
                        "            self.testAPI = testAPI\n" +
                        "            self.component = component\n" +
                        "        def __nonzero__(self):\n" +
                        "            return self.component\n";

                // add verbs methods to the ComponentWrapper class
                Collection<String> verbs = testAPI.getRegisteredVerbs(component);
                for (String verb : verbs) {
                    code += "        def " + verb + "(self, *arguments, **keywords):\n" +
                            "            if self.component:\n";

                    code += "                return self.testAPI._TestAPIWrapper__invoke(self.component." + verb + ", arguments)\n";
View Full Code Here

    }

    private void buildTree(final DefaultMutableTreeNode rootNode, TestAPIDocsTree tree) {
        Thread t = new Thread() {
            public void run() {
                TestAPI testAPI = TestAPIImpl.getInstance();
                rootNode.removeAllChildren();
                ComponentsLoader.getInstance(); // don't remove, it is to be sure that components are registered
                Collection<String> hashComponents = testAPI.getRegisteredComponents();
                TreeSet<String> sortedComponents = new TreeSet<String>(hashComponents);
                TestBedConfiguration testbedConfig = TestBedConfiguration.getInstance();
                for (String componentName: sortedComponents) {
                    boolean componentPresentInTestbed = true;
                    ComponentFactory componentFactory = testAPI.getComponentFactory(componentName);
                    if (componentFactory instanceof SingletonComponentFactory) {
                        componentPresentInTestbed = !testbedConfig.configurationsAt("singleton_components." + componentName).isEmpty();
                    } else if (componentFactory instanceof MultipleInstancesComponentFactory) {
                        componentPresentInTestbed = !testbedConfig.configurationsAt("multiple_instances_components." + componentName).isEmpty();
                    }
                    if (componentPresentInTestbed) {
                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(componentName, true);
                        rootNode.add(node);
                        // get all methods from this component
                        List<String> methods = new ArrayList<String>(testAPI.getRegisteredVerbs(componentName));
                        Collections.sort(methods);
                        for (String methodName: methods) {
                            DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(methodName, true);
                            node.add(childNode);
                        }
View Full Code Here

TOP

Related Classes of com.qspin.qtaste.kernel.testapi.TestAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.