You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/10/25 20:55:47 UTC

svn commit: r1027233 - in /wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax: InternalErrorCallsAjaxOnFailurePage.html InternalErrorCallsAjaxOnFailurePage.java InternalErrorCallsAjaxOnFailureTest.java

Author: mgrigorov
Date: Mon Oct 25 18:55:47 2010
New Revision: 1027233

URL: http://svn.apache.org/viewvc?rev=1027233&view=rev
Log:
Add a unit test for internal errors in Ajax requests

Added:
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java   (with props)

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html?rev=1027233&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html Mon Oct 25 18:55:47 2010
@@ -0,0 +1,6 @@
+<html>
+
+	<body>
+		<a wicket:id="failure-link">link</a>
+	</body>
+</html>
\ No newline at end of file

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java?rev=1027233&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java Mon Oct 25 18:55:47 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.wicket.ajax;
+
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebPage;
+
+public final class InternalErrorCallsAjaxOnFailurePage extends WebPage
+{
+
+	static final String ERROR_MESSAGE = "Failure link clicked";
+
+	public InternalErrorCallsAjaxOnFailurePage()
+	{
+		add(new AjaxLink<Void>("failure-link")
+		{
+			private static final long serialVersionUID = 1L;
+
+			@Override
+			public void onClick(AjaxRequestTarget target)
+			{
+				throw new WicketRuntimeException(ERROR_MESSAGE);
+			}
+		});
+
+	}
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailurePage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java?rev=1027233&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java Mon Oct 25 18:55:47 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+package org.apache.wicket.ajax;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.wicket.protocol.http.mock.MockHttpServletResponse;
+import org.apache.wicket.util.tester.BaseWicketTester;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Test;
+
+/**
+ * Tests that for internal errors in Ajax requests Wicket will send the error response immediately
+ * (RedirectPolicy.NEVER_REDIRECT). Since WicketTester initializes new MockHttpServletResponse after
+ * a request the response with the error is the last one in
+ * {@link BaseWicketTester#getPreviousResponses()}
+ */
+public class InternalErrorCallsAjaxOnFailureTest
+{
+
+	@Test
+	public void callsOnFailure()
+	{
+
+		WicketTester tester = new WicketTester();
+		tester.setExposeExceptions(false);
+		tester.startPage(InternalErrorCallsAjaxOnFailurePage.class);
+
+		tester.clickLink("failure-link", true);
+
+		// the response before current should holds the error page markup
+		List<MockHttpServletResponse> previousResponses = tester.getPreviousResponses();
+		MockHttpServletResponse errorPageResponse = previousResponses.get(previousResponses.size() - 1);
+		assertTrue(errorPageResponse.getDocument().contains(
+			InternalErrorCallsAjaxOnFailurePage.ERROR_MESSAGE));
+	}
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/ajax/InternalErrorCallsAjaxOnFailureTest.java
------------------------------------------------------------------------------
    svn:eol-style = native