From: Matti Tahvonen Date: Tue, 11 Dec 2007 13:42:43 +0000 (+0000) Subject: some steps towards Testing Tools supports X-Git-Tag: 6.7.0.beta1~5245 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a6827616b43aeb1f6a4817081bb2765dac90a0f;p=vaadin-framework.git some steps towards Testing Tools supports svn changeset:3217/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 73902dc150..0fc3b76b6b 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -58,6 +58,12 @@ public class ApplicationConnection { private final IView view; + /** + * True if each Paintable objects id is injected to DOM. Used for Testing + * Tools. + */ + private boolean usePaintableIdsInDOM = false; + public ApplicationConnection(WidgetSet widgetSet) { this.widgetSet = widgetSet; appUri = getAppUri(); @@ -68,6 +74,10 @@ public class ApplicationConnection { console = new NullConsole(); } + if (isTestingMode()) { + usePaintableIdsInDOM = true; + } + makeUidlRequest("repaintAll=1"); // TODO remove hardcoded id name @@ -75,6 +85,15 @@ public class ApplicationConnection { } + private native static boolean isTestingMode() + /*-{ + return $wnd.itmill.testingToolsUri ? true : false; + }-*/; + + private native static void initializeTestingTools(String uri) + /*-{ + }-*/; + public static Console getConsole() { return console; } @@ -531,6 +550,10 @@ public class ApplicationConnection { } } + if (usePaintableIdsInDOM) { + DOM.setElementProperty(component.getElement(), "id", uidl.getId()); + } + return false; } diff --git a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java index 3c7b93d52f..20a46b34aa 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java @@ -10,9 +10,11 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.io.Writer; import java.lang.reflect.Constructor; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; @@ -125,6 +127,10 @@ public class ApplicationServlet extends HttpServlet { private ClassLoader classLoader; + private boolean testingToolsActive = false; + + private String testingToolsServerUri = null; + /** * Called by the servlet container to indicate to a servlet that the servlet * is being placed into service. @@ -184,6 +190,14 @@ public class ApplicationServlet extends HttpServlet { } debugMode = debug; + // Gets ATF parameters if feature is activated + if (getApplicationOrSystemProperty("testingToolsActive", "false") + .equals("true")) { + testingToolsActive = true; + testingToolsServerUri = getApplicationOrSystemProperty( + "testingToolsServerUri", null); + } + // Gets custom class loader final String classLoaderName = getApplicationOrSystemProperty( "ClassLoader", null); @@ -226,6 +240,7 @@ public class ApplicationServlet extends HttpServlet { // This servlet is in application runner mode, it uses classloader // later to create Applications based on URL } + } /** @@ -649,11 +664,25 @@ public class ApplicationServlet extends HttpServlet { themeUri = staticFilePath + "/" + THEME_DIRECTORY_PATH + themeName; } - page.write("', pathInfo: '" + pathInfo + "', themeUri: " - + (themeUri != null ? "'" + themeUri + "'" : "null") + "\n};\n" - + "\n" + "\n"); + boolean testingWindow = testingToolsActive + && request.getParameter("TT") != null; + + page.write("', pathInfo: '" + pathInfo); + page.write("', themeUri: "); + page.write(themeUri != null ? "'" + themeUri + "'" : "null"); + if (testingWindow) { + page.write(", testingToolsUri : '" + getTestingToolsUri() + "'"); + } + + page.write("\n};\n\n"); + + if (testingWindow) { + writeTestingToolsScripts(page, request); + } + + page.write("\n"); if (themeName != null) { // Custom theme's stylesheet @@ -671,6 +700,113 @@ public class ApplicationServlet extends HttpServlet { } + private void writeTestingToolsScripts(Writer page, + HttpServletRequest request) throws IOException { + // ATF script and CSS files are served from ATFServer + String ext = getTestingToolsUri(); + ext = ext.substring(0, ext.lastIndexOf('/')); + page.write("\n"); + page.write("\n"); + if (request.getParameter("ATF-TC") != null + || request.getParameter("ATF-TS") != null) { + proxyTestCases(request.getParameter("ATF-TC"), request + .getParameter("ATF-TS"), request + .getParameter("ATF-TS-RUN-ID"), page); + } + } + + private String getTestingToolsUri() { + if (testingToolsServerUri == null) { + // Default behavior is that ATFServer application exists on + // same application server as current application does. + testingToolsServerUri = "/ATF/ATFServer"; + } + return testingToolsServerUri; + } + + /** + * Fetches testcase or testsuite scripts from ATF server and injects script + * to AUT client + * + * @param testCaseId + * @param testSuiteId + * @param testSuiteRunId + * @param page + * @throws IOException + * @throws MalformedURLException + */ + private void proxyTestCases(String testCaseId, String testSuiteId, + String testSuiteRunId, Writer page) throws IOException, + MalformedURLException { + URLConnection conn; + + String testCaseProviderURL = getTestingToolsUri(); + if (testCaseId != null) { + testCaseProviderURL += "/ATF-TC/" + testCaseId; + } + if (testSuiteId != null) { + testCaseProviderURL += "/ATF-TS/" + testSuiteId; + } + if (testSuiteRunId != null) { + testCaseProviderURL += "/ATF-TS-RUN-ID/" + testSuiteRunId; + } + + conn = new URL(testCaseProviderURL).openConnection(); + InputStream is = conn.getInputStream(); + + StringBuffer builder = new StringBuffer(); + byte[] b = new byte[4096]; + for (int n; (n = is.read(b)) != -1;) { + builder.append(new String(b, 0, n)); + } + is.close(); + + if (builder != null && builder.length() > 0 + && builder.toString().startsWith("ATF-TC=")) { + int lineEnd = builder.indexOf("\n"); + String returnedTestCaseId = builder.substring(builder + .indexOf("ATF-TC=") + 7, lineEnd); + builder.replace(0, lineEnd + 1, ""); + + String returnedTestSuiteRunId = null; + + if (testSuiteId != null) { + lineEnd = builder.indexOf("\n"); + returnedTestSuiteRunId = builder.substring(builder + .indexOf("ATF-TS-RUN-ID=") + 14, lineEnd); + } + + if (builder.length() < lineEnd + 1) { + throw new RuntimeException( + "The received testscript is illegal. Expected testcase script id in first line " + + " and the actual script in following lines. The script: " + + builder.toString()); + } + + page + .write("\n"); + } + } + /** * Handles the requested URI. An application can add handlers to do special * processing, when a certain URI is requested. The handlers are invoked