You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/06/18 16:11:50 UTC
svn commit: r786069 - in /myfaces/tobago/trunk/example/test/src:
main/java/org/apache/myfaces/tobago/example/test/ main/webapp/
main/webapp/meta-test/ main/webapp/script/
test/java/org/apache/myfaces/tobago/example/test/
Author: lofwyr
Date: Thu Jun 18 14:11:49 2009
New Revision: 786069
URL: http://svn.apache.org/viewvc?rev=786069&view=rev
Log:
TOBAGO-765: Test the AutomaticTest
Added:
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-0-ok.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-1-fail.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-2-ok.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-3-ok.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-4-not-tobago.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/script/
myfaces/tobago/trunk/example/test/src/main/webapp/script/test-utils.js
myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java
Modified:
myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java
myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml
myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java
myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java
Modified: myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java?rev=786069&r1=786068&r2=786069&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java (original)
+++ myfaces/tobago/trunk/example/test/src/main/java/org/apache/myfaces/tobago/example/test/Filter.java Thu Jun 18 14:11:49 2009
@@ -29,17 +29,29 @@
private static final Log LOG = LogFactory.getLog(Filter.class);
- public static final List<String> ALLOWED = Arrays.asList(".*\\.xhtml", ".*\\.jsp", ".*\\.jspx", ".*\\.html");
+ public static final List<String> ALLOWED = Arrays.asList(
+ ".*\\.xhtml",
+ ".*\\.jsp",
+ ".*\\.jspx",
+ ".*\\.html"
+ );
public static final Set<String> FORBIDDEN = new HashSet<String>(Arrays.asList(
"/META-INF.*",
"/WEB-INF.*",
"/index.html",
- "/navi.xhtml",
+ "/meta-test/meta-1.*",
+ "/meta-test/meta-2.*\\.jspx",
+ "/meta-test/meta-3.*\\.xhtml",
+ "/meta-test/meta-4.*",
+ "/navi.*",
"/org/apache/myfaces/tobago/renderkit/html/standard/blank.html",
"/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/dojo/.*",
"/tc/button/plain.html",
- "/tc/button/plain_de.html"));
+ "/tc/button/plain_de.html",
+ "/tc/gridLayout/horizontal-600px-default-300px.*",
+ "/tc/gridLayout/horizontal-default-default-600px.*"
+ ));
public static boolean isValid(String name) {
Added: myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-0-ok.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-0-ok.xhtml?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-0-ok.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-0-ok.xhtml Thu Jun 18 14:11:49 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<f:view
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page id="page">
+
+ <tc:out value="Test of the automatic test system."/>
+
+ </tc:page>
+
+</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-1-fail.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-1-fail.xhtml?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-1-fail.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-1-fail.xhtml Thu Jun 18 14:11:49 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<f:view
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:f="http://java.sun.com/jsf/core">
+ Test of the automatic test system.
+
+ This test will fail!
+
+ <tc:page id="page">
+
+ <tc:script file="script/test-utils.js"/>
+ <tc:script onload="checkWidth('page', 600);"/>
+
+ </tc:page>
+
+</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-2-ok.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-2-ok.xhtml?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-2-ok.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-2-ok.xhtml Thu Jun 18 14:11:49 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<f:view
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page id="page">
+
+ <tc:out value="Test of the automatic test system."/>
+
+ </tc:page>
+
+</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-3-ok.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-3-ok.xhtml?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-3-ok.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-3-ok.xhtml Thu Jun 18 14:11:49 2009
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+<f:view
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page id="page">
+
+ <tc:out value="Test of the automatic test system."/>
+
+ </tc:page>
+
+</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-4-not-tobago.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-4-not-tobago.xhtml?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-4-not-tobago.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/meta-test/meta-4-not-tobago.xhtml Thu Jun 18 14:11:49 2009
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+-->
+
+
+<f:view
+ xmlns:f="http://java.sun.com/jsf/core">
+ <html>
+ <body> Test of the automatic test system.
+ </body>
+ </html>
+</f:view>
+
Modified: myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml?rev=786069&r1=786068&r2=786069&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml (original)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/navi.xhtml Thu Jun 18 14:11:49 2009
@@ -7,20 +7,15 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
- <tc:page id="page" label="XXX" width="300px" height="700px">
+ <tc:page id="page" label="XXX">
<f:facet name="layout">
- <tc:gridLayout/>
+ <tc:gridLayout rows="fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed;fixed"/>
</f:facet>
- <tc:sheet value="#{browser.list}" columns="*" var="item" rows="1000">
- <tc:column label="Test Pages">
- <tc:link link="#{item.resource}" label="#{item.label}" target="test"/>
-<!--
-todo: this will work in later versions
- <tc:link resource="#{item.resource}" jsfResource="#{item.jsfResource}" label="#{item.label}" target="test"/>
--->
- </tc:column>
- </tc:sheet>
+ <ui:repeat value="#{browser.list}" var="path">
+ <tc:link link="#{path.resource}" label="#{path.label}" target="test"/>
+ <tc:out value="<br/>" escape="false"/>
+ </ui:repeat>
</tc:page>
</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/script/test-utils.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/script/test-utils.js?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/script/test-utils.js (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/script/test-utils.js Thu Jun 18 14:11:49 2009
@@ -0,0 +1,42 @@
+/*
+ * Utilities to make client side tests easier.
+ */
+
+function checkLeft(id, left) {
+ var offsetLeft = document.getElementById(id).offsetLeft;
+ if (offsetLeft != left) {
+ LOG.error("The element with id=" + id + " has wrong left: expected=" + left
+ + " actual=" + offsetLeft);
+ }
+}
+
+function checkTop(id, top) {
+ var offsetTop = document.getElementById(id).offsetTop;
+ if (offsetTop != top) {
+ LOG.error("The element with id=" + id + " has wrong top: expected=" + top
+ + " actual=" + offsetTop);
+ }
+}
+
+function checkWidth(id, width) {
+ var offsetWidth = document.getElementById(id).offsetWidth;
+ if (offsetWidth != width) {
+ LOG.error("The element with id=" + id + " has wrong width: expected=" + width
+ + " actual=" + offsetWidth);
+ }
+}
+
+function checkHeight(id, height) {
+ var offsetHeight = document.getElementById(id).offsetHeight;
+ if (offsetHeight != height) {
+ LOG.error("The element with id=" + id + " has wrong height: expected=" + height
+ + " actual=" + offsetHeight);
+ }
+}
+
+function checkLayout(id, left, top, width, height) {
+ checkLeft(id, left);
+ checkTop(id, top);
+ checkWidth(id, width);
+ checkHeight(id, height);
+}
Modified: myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java?rev=786069&r1=786068&r2=786069&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java (original)
+++ myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java Thu Jun 18 14:11:49 2009
@@ -30,11 +30,15 @@
@RunWith(Parameterized.class)
public class AutomaticSeleniumTest extends SeleniumTest {
+ static final String CONTAINS_A_404 = "contains a 404";
+ static final String HAS_ERROR_SEVERITY = "has error severity";
+
private static final String MAVEN_TARGET = "target/tobago-example-test";
private static final String CONTEXT_PATH = "tobago-example-test";
private static final String SERVLET_MAPPING = "faces";
private String url;
+ static final String IS_BROKEN = "is broken";
public AutomaticSeleniumTest(String title, String url) {
this.url = url;
@@ -42,12 +46,13 @@
@Test
public void testPageConsistency() {
+
selenium.open(url);
- Assert.assertFalse("Page '" + url + "' contains a 404. Source=" + selenium.getHtmlSource(), pageNotFound());
+ Assert.assertFalse("Page '" + url + "' " + CONTAINS_A_404 + ". Source=" + selenium.getHtmlSource(), pageNotFound());
try {
- Assert.assertFalse("Page '" + url + "' has error severity. Source=" + selenium.getHtmlSource(), isErrorOnPage());
+ Assert.assertFalse("Page '" + url + "' " + HAS_ERROR_SEVERITY + ". Source=" + selenium.getHtmlSource(), isErrorOnPage());
} catch (SeleniumException e) {
- Assert.fail("Page '" + url + "' is broken. Not a Tobago page? Source=" + selenium.getHtmlSource() + " exception=" + e);
+ Assert.fail("Page '" + url + "' " + IS_BROKEN + ". Not a Tobago page? Source=" + selenium.getHtmlSource() + " exception=" + e);
}
}
@@ -104,7 +109,8 @@
}
protected static String createUrl(String page) {
- return '/' + CONTEXT_PATH + '/' + SERVLET_MAPPING + '/' + page;
+ Assert.assertTrue("Page name must start with a slash.", page.startsWith("/"));
+ return '/' + CONTEXT_PATH + '/' + SERVLET_MAPPING + page;
}
}
Modified: myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java?rev=786069&r1=786068&r2=786069&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java (original)
+++ myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/FilterUnitTest.java Thu Jun 18 14:11:49 2009
@@ -36,6 +36,6 @@
Assert.assertFalse(Filter.isValid("/META-INF/"));
Assert.assertFalse(Filter.isValid("/navi.xhtml"));
- Assert.assertTrue(Filter.isValid("/navi-2.xhtml"));
+ Assert.assertTrue(Filter.isValid("/nav.xhtml"));
}
}
Added: myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java?rev=786069&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java (added)
+++ myfaces/tobago/trunk/example/test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java Thu Jun 18 14:11:49 2009
@@ -0,0 +1,116 @@
+package org.apache.myfaces.tobago.example.test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class TestTheAutomaticSeleniumTest {
+
+ private static final Log LOG = LogFactory.getLog(TestTheAutomaticSeleniumTest.class);
+
+ @Test
+ public void areTheCorrectFilesTested() {
+
+ List<String> metaTestList = new ArrayList<String>();
+
+ Collection<Object[]> pages = AutomaticSeleniumTest.findPages();
+ for (Object[] page : pages) {
+ String url = (String) page[1];
+ String prefix = "/tobago-example-test/faces/meta-test/";
+ if (url.startsWith(prefix)) {
+ metaTestList.add(url.substring(prefix.length()));
+ }
+ }
+
+ Collections.sort(metaTestList);
+
+ String[] expected = new String[]{
+ "meta-0-ok.jspx",
+ "meta-0-ok.xhtml",
+ "meta-2-ok.xhtml",
+ "meta-3-ok.jspx"
+ };
+
+ Assert.assertArrayEquals(expected, metaTestList.toArray());
+ }
+
+ @Test
+ public void test404() throws Exception {
+ try {
+ String url = AutomaticSeleniumTest.createUrl("/meta-test/meta-404-not-existing.xhtml");
+ LOG.info("Testing page: '" + url + "'");
+ AutomaticSeleniumTest test = new AutomaticSeleniumTest(url, url);
+ test.setUp();
+ test.testPageConsistency();
+ test.tearDown();
+ Assert.fail("The test should has been failed.");
+ } catch (AssertionError e) {
+ if (e.getMessage().contains(AutomaticSeleniumTest.CONTAINS_A_404)) {
+ // okay, the error was detected.
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testErrorSeverity() throws Exception {
+ try {
+ String url = AutomaticSeleniumTest.createUrl("/meta-test/meta-1-fail.xhtml");
+ LOG.info("Testing page: '" + url + "'");
+ AutomaticSeleniumTest test = new AutomaticSeleniumTest(url, url);
+ test.setUp();
+ test.testPageConsistency();
+ test.tearDown();
+ Assert.fail("The test should has been failed.");
+ } catch (AssertionError e) {
+ if (e.getMessage().contains(AutomaticSeleniumTest.HAS_ERROR_SEVERITY)) {
+ // okay, the error was detected.
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ @Test
+ public void testNotTobago() throws Exception {
+ try {
+ String url = AutomaticSeleniumTest.createUrl("/meta-test/meta-4-not-tobago.xhtml");
+ LOG.info("Testing page: '" + url + "'");
+ AutomaticSeleniumTest test = new AutomaticSeleniumTest(url, url);
+ test.setUp();
+ test.testPageConsistency();
+ test.tearDown();
+ Assert.fail("The test should has been failed.");
+ } catch (AssertionError e) {
+ if (e.getMessage().contains(AutomaticSeleniumTest.IS_BROKEN)) {
+ // okay, the error was detected.
+ } else {
+ throw e;
+ }
+ }
+ }
+}