Author: grobmeier
Date: Sun Mar 17 07:45:59 2013
New Revision: 1457393
URL: http://svn.apache.org/r1457393
Log:
WW-4017: Support multiple Action executions and Session values
Added:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java
(with props)
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java
(with props)
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java
(with props)
struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml
(with props)
struts/struts2/trunk/plugins/junit/src/test/resources/template-session.ftl
Added:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java?rev=1457393&view=auto
==============================================================================
---
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java
(added)
+++
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java
Sun Mar 17 07:45:59 2013
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.session;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+/**
+ * An action which reads a value from the session.
+ * The value is previously set by SessionSetAction.
+ */
+public class SessionGetAction extends ActionSupport {
+ private static final long serialVersionUID = 8366502863472148631L;
+
+ public String execute() {
+ return ActionSupport.SUCCESS;
+ }
+}
Propchange:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionGetAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java?rev=1457393&view=auto
==============================================================================
---
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java
(added)
+++
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java
Sun Mar 17 07:45:59 2013
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.session;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionSupport;
+
+/**
+ * An action which sets a value into the session
+ */
+public class SessionSetAction extends ActionSupport {
+ private static final long serialVersionUID = -3097127804272607687L;
+
+ public String SESSION_KEY = "sessionKey";
+ public String SESSION_VALUE = "sessionValue";
+
+ public String execute() {
+ ActionContext.getContext().getSession().put(SESSION_KEY,
SESSION_VALUE);
+ return ActionSupport.SUCCESS;
+ }
+}
Propchange:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/SessionSetAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java?rev=1457393&view=auto
==============================================================================
---
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java
(added)
+++
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java
Sun Mar 17 07:45:59 2013
@@ -0,0 +1,53 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.session;
+
+import org.apache.struts2.JUnitTestAction;
+import org.apache.struts2.StrutsJUnit4TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Calls SessionSet which sets a value into the session and afterwards calls
SessionGet, which
+ * should return this session value.
+ *
+ * In prior versions only one executeAction() call could happen in a single
test case, because
+ * either the session values were deleted or the wrong result would be
returned (always the result of
+ * the first action execution).
+ */
+public class StrutsJUnit4SessionTestCaseTest extends
StrutsJUnit4TestCase<JUnitTestAction>{
+ @Test
+ public void testPersistingSessionValues() throws Exception {
+ String output = executeAction("/sessiontest/sessionSet.action");
+ Assert.assertEquals("sessionValue", output);
+
+ this.finishExecution();
+
+ String output2 = executeAction("/sessiontest/sessionGet.action");
+ Assert.assertEquals("sessionValue", output2);
+ }
+
+ @Override
+ protected String getConfigPath() {
+ return "struts-session-values-test.xml";
+ }
+}
Propchange:
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/session/StrutsJUnit4SessionTestCaseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml?rev=1457393&view=auto
==============================================================================
---
struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml
(added)
+++
struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml
Sun Mar 17 07:45:59 2013
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+ ~ $Id$
+ ~
+ ~ 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.
+ -->
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
+ "http://struts.apache.org/dtds/struts-2.1.dtd">
+
+<struts>
+ <package name="test" namespace="/sessiontest" extends="struts-default">
+ <action name="sessionSet"
class="org.apache.struts2.session.SessionSetAction">
+ <result type="freemarker">/template-session.ftl</result>
+ </action>
+ <action name="sessionGet"
class="org.apache.struts2.session.SessionGetAction">
+ <result type="freemarker">/template-session.ftl</result>
+ </action>
+ </package>
+</struts>
Propchange:
struts/struts2/trunk/plugins/junit/src/test/resources/struts-session-values-test.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
struts/struts2/trunk/plugins/junit/src/test/resources/template-session.ftl
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/test/resources/template-session.ftl?rev=1457393&view=auto
==============================================================================
--- struts/struts2/trunk/plugins/junit/src/test/resources/template-session.ftl
(added)
+++ struts/struts2/trunk/plugins/junit/src/test/resources/template-session.ftl
Sun Mar 17 07:45:59 2013
@@ -0,0 +1,21 @@
+<#--
+ ~ $Id:$
+ ~
+ ~ 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.
+ -->
+${Session.sessionKey}
\ No newline at end of file