001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.tools.seleniumbuilder;
016    
017    import com.liferay.portal.kernel.util.SetUtil;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.xml.Element;
020    import com.liferay.portal.tools.ArgumentsUtil;
021    import com.liferay.portal.util.InitUtil;
022    
023    import java.util.List;
024    import java.util.Map;
025    import java.util.Set;
026    
027    /**
028     * @author Michael Hashimoto
029     */
030    public class SeleniumBuilder {
031    
032            public static void main(String[] args) throws Exception {
033                    InitUtil.initWithSpring();
034    
035                    new SeleniumBuilder(args);
036            }
037    
038            public SeleniumBuilder(String[] args) throws Exception {
039                    Map<String, String> arguments = ArgumentsUtil.parseArguments(args);
040    
041                    String baseDir = arguments.get("selenium.base.dir");
042    
043                    SeleniumBuilderContext seleniumBuilderContext =
044                            new SeleniumBuilderContext(baseDir);
045    
046                    Set<String> types = SetUtil.fromArray(
047                            StringUtil.split(arguments.get("selenium.types")));
048    
049                    if (types.contains("action")) {
050                            ActionConverter actionConverter = new ActionConverter(
051                                    seleniumBuilderContext);
052    
053                            Set<String> actionNames = seleniumBuilderContext.getActionNames();
054    
055                            for (String actionName : actionNames) {
056                                    seleniumBuilderContext.validateActionElements(actionName);
057    
058                                    actionConverter.convert(actionName);
059                            }
060                    }
061    
062                    if (types.contains("function")) {
063                            FunctionConverter functionConverter = new FunctionConverter(
064                                    seleniumBuilderContext);
065    
066                            Set<String> functionNames =
067                                    seleniumBuilderContext.getFunctionNames();
068    
069                            for (String functionName : functionNames) {
070                                    seleniumBuilderContext.validateFunctionElements(functionName);
071    
072                                    functionConverter.convert(functionName);
073                            }
074                    }
075    
076                    if (types.contains("macro")) {
077                            MacroConverter macroConverter = new MacroConverter(
078                                    seleniumBuilderContext);
079    
080                            Set<String> macroNames = seleniumBuilderContext.getMacroNames();
081    
082                            for (String macroName : macroNames) {
083                                    seleniumBuilderContext.validateMacroElements(macroName);
084    
085                                    macroConverter.convert(macroName);
086                            }
087                    }
088    
089                    if (types.contains("path")) {
090                            PathConverter pathConverter = new PathConverter(
091                                    seleniumBuilderContext);
092    
093                            Set<String> pathNames = seleniumBuilderContext.getPathNames();
094    
095                            for (String pathName : pathNames) {
096                                    pathConverter.convert(pathName);
097                            }
098                    }
099    
100                    if (types.contains("testcase")) {
101                            TestCaseConverter testCaseConverter = new TestCaseConverter(
102                                    seleniumBuilderContext);
103    
104                            Set<String> testCaseNames =
105                                    seleniumBuilderContext.getTestCaseNames();
106    
107                            for (String testCaseName : testCaseNames) {
108                                    seleniumBuilderContext.validateTestCaseElements(testCaseName);
109    
110                                    testCaseConverter.convert(testCaseName);
111                            }
112                    }
113    
114                    if (types.contains("testsuite")) {
115                            TestSuiteConverter testSuiteConverter = new TestSuiteConverter(
116                                    seleniumBuilderContext);
117    
118                            Set<String> testSuiteNames =
119                                    seleniumBuilderContext.getTestSuiteNames();
120    
121                            for (String testSuiteName : testSuiteNames) {
122                                    seleniumBuilderContext.validateTestSuiteElements(testSuiteName);
123    
124                                    testSuiteConverter.convert(testSuiteName);
125                            }
126                    }
127    
128                    SeleniumBuilderFileUtil seleniumBuilderFileUtil =
129                            new SeleniumBuilderFileUtil(baseDir);
130    
131                    int testCaseCount = 0;
132    
133                    Set<String> testCaseNames = seleniumBuilderContext.getTestCaseNames();
134    
135                    for (String testCaseName : testCaseNames) {
136                            Element rootElement = seleniumBuilderContext.getTestCaseRootElement(
137                                    testCaseName);
138    
139                            List<Element> commandElements =
140                                    seleniumBuilderFileUtil.getAllChildElements(
141                                            rootElement, "command");
142    
143                            testCaseCount += commandElements.size();
144                    }
145    
146                    System.out.println("\nThere are " + testCaseCount + " test cases.");
147            }
148    
149    }