You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Lukasz Lenart <lu...@apache.org> on 2015/10/13 10:51:42 UTC
Re: struts git commit: Cleaned up project to be buildable with jdk8.
Moved StrutsPortletTestCase to src/test where it belongs! Declared
dependencies -junit-plugin and junit as scope test, as it should be.
This class must stay where it was - it is a base class for users' unit
tests - without it they won't be able to write unit tests to test
portlets. A release doesn't contain the test classes, there is no jar
with them.
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
2015-10-13 10:21 GMT+02:00 <cn...@apache.org>:
> Repository: struts
> Updated Branches:
> refs/heads/master 0dd0f045d -> 4bff5a874
>
>
> Cleaned up project to be buildable with jdk8. Moved StrutsPortletTestCase to src/test where it belongs! Declared dependencies -junit-plugin and junit as scope test, as it should be.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/struts/repo
> Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/4bff5a87
> Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/4bff5a87
> Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/4bff5a87
>
> Branch: refs/heads/master
> Commit: 4bff5a87486b67a6da0f7703af574f2eff65e036
> Parents: 0dd0f04
> Author: cnenning <cn...@apache.org>
> Authored: Tue Oct 13 10:21:43 2015 +0200
> Committer: cnenning <cn...@apache.org>
> Committed: Tue Oct 13 10:21:43 2015 +0200
>
> ----------------------------------------------------------------------
> plugins/portlet/pom.xml | 27 +++---
> .../apache/struts2/StrutsPortletTestCase.java | 90 -------------------
> .../struts2/portlet/StrutsPortletTestCase.java | 94 ++++++++++++++++++++
> 3 files changed, 109 insertions(+), 102 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/struts/blob/4bff5a87/plugins/portlet/pom.xml
> ----------------------------------------------------------------------
> diff --git a/plugins/portlet/pom.xml b/plugins/portlet/pom.xml
> index da5a8ca..f3f71a2 100644
> --- a/plugins/portlet/pom.xml
> +++ b/plugins/portlet/pom.xml
> @@ -12,18 +12,6 @@
>
> <dependencies>
> <dependency>
> - <groupId>org.apache.struts</groupId>
> - <artifactId>struts2-junit-plugin</artifactId>
> - <optional>true</optional>
> - </dependency>
> -
> - <dependency>
> - <groupId>junit</groupId>
> - <artifactId>junit</artifactId>
> - <optional>true</optional>
> - </dependency>
> -
> - <dependency>
> <groupId>javax.servlet</groupId>
> <artifactId>jsp-api</artifactId>
> <scope>provided</scope>
> @@ -54,6 +42,21 @@
> <scope>provided</scope>
> </dependency>
>
> + <!-- tests -->
> + <dependency>
> + <groupId>org.apache.struts</groupId>
> + <artifactId>struts2-junit-plugin</artifactId>
> + <optional>true</optional>
> + <scope>test</scope>
> + </dependency>
> +
> + <dependency>
> + <groupId>junit</groupId>
> + <artifactId>junit</artifactId>
> + <optional>true</optional>
> + <scope>test</scope>
> + </dependency>
> +
> <dependency>
> <groupId>mockobjects</groupId>
> <artifactId>mockobjects-jdk1.3-j2ee1.3</artifactId>
>
> http://git-wip-us.apache.org/repos/asf/struts/blob/4bff5a87/plugins/portlet/src/main/java/org/apache/struts2/StrutsPortletTestCase.java
> ----------------------------------------------------------------------
> diff --git a/plugins/portlet/src/main/java/org/apache/struts2/StrutsPortletTestCase.java b/plugins/portlet/src/main/java/org/apache/struts2/StrutsPortletTestCase.java
> deleted file mode 100644
> index ad89df1..0000000
> --- a/plugins/portlet/src/main/java/org/apache/struts2/StrutsPortletTestCase.java
> +++ /dev/null
> @@ -1,90 +0,0 @@
> -package org.apache.struts2;
> -
> -import com.opensymphony.xwork2.ActionContext;
> -import org.apache.logging.log4j.Logger;
> -import org.apache.logging.log4j.LogManager;
> -import org.apache.struts2.portlet.PortletConstants;
> -import org.apache.struts2.portlet.PortletPhase;
> -import org.springframework.mock.web.portlet.MockPortletContext;
> -import org.springframework.mock.web.portlet.MockPortletRequest;
> -import org.springframework.mock.web.portlet.MockPortletResponse;
> -import org.springframework.mock.web.portlet.MockPortletSession;
> -import org.springframework.mock.web.portlet.MockStateAwareResponse;
> -
> -import javax.portlet.PortletMode;
> -import java.util.HashMap;
> -import java.util.Map;
> -
> -/**
> - * Base class used to test action in portlet environment
> - */
> -public abstract class StrutsPortletTestCase extends StrutsTestCase {
> -
> - private static final Logger LOG = LogManager.getLogger(StrutsPortletTestCase.class);
> -
> - protected MockPortletSession portletSession;
> - protected MockPortletRequest portletRequest;
> - protected MockPortletResponse portletResponse;
> - protected MockContext portletContext;
> -
> - @Override
> - protected void initActionContext(ActionContext actionContext) {
> - super.initActionContext(actionContext);
> - initPortletContext(actionContext);
> - }
> -
> - protected void initPortletContext(ActionContext actionContext) {
> - LOG.debug("Initializing mock portlet environment");
> - portletContext = new MockContext();
> - portletContext.setMajorVersion(getMajorVersion());
> - actionContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletContext);
> -
> - portletRequest = new MockPortletRequest(portletContext);
> - portletResponse = new MockStateAwareResponse();
> - portletSession = new MockPortletSession();
> - portletRequest.setSession(portletSession);
> - actionContext.setSession(createSession());
> - actionContext.put(PortletConstants.REQUEST, portletRequest);
> - actionContext.put(PortletConstants.RESPONSE, portletResponse);
> - actionContext.put(PortletConstants.MODE_NAMESPACE_MAP, new HashMap<PortletMode, String>());
> - actionContext.put(PortletConstants.PHASE, PortletPhase.EVENT_PHASE);
> - }
> -
> - /**
> - * Override to define version of your portlet environment
> - *
> - * @return portlet version
> - */
> - protected int getMajorVersion() {
> - return 2;
> - }
> -
> - /**
> - * Override to create your own session
> - *
> - * @return Map with session parameters
> - */
> - private Map<String, Object> createSession() {
> - return new HashMap<String, Object>(portletRequest.getPortletSession().getAttributeMap());
> - }
> -
> -}
> -
> -/**
> - * Simple workaround to define Portlet version
> - */
> -class MockContext extends MockPortletContext {
> -
> - private int majorVersion;
> -
> - @Override
> - public int getMajorVersion() {
> - return majorVersion;
> - }
> -
> - public void setMajorVersion(int majorVersion) {
> - this.majorVersion = majorVersion;
> - }
> -
> -}
> -
>
> http://git-wip-us.apache.org/repos/asf/struts/blob/4bff5a87/plugins/portlet/src/test/java/org/apache/struts2/portlet/StrutsPortletTestCase.java
> ----------------------------------------------------------------------
> diff --git a/plugins/portlet/src/test/java/org/apache/struts2/portlet/StrutsPortletTestCase.java b/plugins/portlet/src/test/java/org/apache/struts2/portlet/StrutsPortletTestCase.java
> new file mode 100644
> index 0000000..a4bb71c
> --- /dev/null
> +++ b/plugins/portlet/src/test/java/org/apache/struts2/portlet/StrutsPortletTestCase.java
> @@ -0,0 +1,94 @@
> +package org.apache.struts2.portlet;
> +
> +import com.opensymphony.xwork2.ActionContext;
> +
> +import org.apache.logging.log4j.Logger;
> +import org.apache.logging.log4j.LogManager;
> +import org.apache.struts2.StrutsStatics;
> +import org.apache.struts2.StrutsTestCase;
> +import org.apache.struts2.portlet.PortletConstants;
> +import org.apache.struts2.portlet.PortletPhase;
> +import org.springframework.mock.web.portlet.MockPortletContext;
> +import org.springframework.mock.web.portlet.MockPortletRequest;
> +import org.springframework.mock.web.portlet.MockPortletResponse;
> +import org.springframework.mock.web.portlet.MockPortletSession;
> +import org.springframework.mock.web.portlet.MockStateAwareResponse;
> +
> +import javax.portlet.PortletMode;
> +
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +/**
> + * Base class used to test action in portlet environment
> + */
> +public abstract class StrutsPortletTestCase extends StrutsTestCase {
> +
> + private static final Logger LOG = LogManager.getLogger(StrutsPortletTestCase.class);
> +
> + protected MockPortletSession portletSession;
> + protected MockPortletRequest portletRequest;
> + protected MockPortletResponse portletResponse;
> + protected MockContext portletContext;
> +
> + @Override
> + protected void initActionContext(ActionContext actionContext) {
> + super.initActionContext(actionContext);
> + initPortletContext(actionContext);
> + }
> +
> + protected void initPortletContext(ActionContext actionContext) {
> + LOG.debug("Initializing mock portlet environment");
> + portletContext = new MockContext();
> + portletContext.setMajorVersion(getMajorVersion());
> + actionContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletContext);
> +
> + portletRequest = new MockPortletRequest(portletContext);
> + portletResponse = new MockStateAwareResponse();
> + portletSession = new MockPortletSession();
> + portletRequest.setSession(portletSession);
> + actionContext.setSession(createSession());
> + actionContext.put(PortletConstants.REQUEST, portletRequest);
> + actionContext.put(PortletConstants.RESPONSE, portletResponse);
> + actionContext.put(PortletConstants.MODE_NAMESPACE_MAP, new HashMap<PortletMode, String>());
> + actionContext.put(PortletConstants.PHASE, PortletPhase.EVENT_PHASE);
> + }
> +
> + /**
> + * Override to define version of your portlet environment
> + *
> + * @return portlet version
> + */
> + protected int getMajorVersion() {
> + return 2;
> + }
> +
> + /**
> + * Override to create your own session
> + *
> + * @return Map with session parameters
> + */
> + private Map<String, Object> createSession() {
> + return new HashMap<String, Object>(portletRequest.getPortletSession().getAttributeMap());
> + }
> +
> +}
> +
> +/**
> + * Simple workaround to define Portlet version
> + */
> +class MockContext extends MockPortletContext {
> +
> + private int majorVersion;
> +
> + @Override
> + public int getMajorVersion() {
> + return majorVersion;
> + }
> +
> + public void setMajorVersion(int majorVersion) {
> + this.majorVersion = majorVersion;
> + }
> +
> +}
> +
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: struts git commit: Cleaned up project to be buildable with jdk8.
Moved StrutsPortletTestCase to src/test where it belongs! Declared
dependencies -junit-plugin and junit as scope test, as it should be.
Posted by Lukasz Lenart <lu...@apache.org>.
2015-10-13 10:57 GMT+02:00 Christoph Nenning <Ch...@lex-com.net>:
>> This class must stay where it was - it is a base class for users' unit
>> tests - without it they won't be able to write unit tests to test
>> portlets. A release doesn't contain the test classes, there is no jar
>> with them.
>>
>
> A test class must live in src/main instead of src/test?
Yes if you (as a user) want to write a test based on it
> The jdk8 build error occurs because portlet plugin has a dependency on
> struts-junit-plugin and junit for the compile scope. This drags in some
> spring jars but not spring-core. If this project really needs such a
> special setup, with test stuff included in main project, then spring-core
> must be added as well.
So let's add it :)
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: struts git commit: Cleaned up project to be buildable with jdk8. Moved
StrutsPortletTestCase to src/test where it belongs! Declared dependencies
-junit-plugin and junit as scope test, as it should be.
Posted by Christoph Nenning <Ch...@lex-com.net>.
> This class must stay where it was - it is a base class for users' unit
> tests - without it they won't be able to write unit tests to test
> portlets. A release doesn't contain the test classes, there is no jar
> with them.
>
A test class must live in src/main instead of src/test?
The jdk8 build error occurs because portlet plugin has a dependency on
struts-junit-plugin and junit for the compile scope. This drags in some
spring jars but not spring-core. If this project really needs such a
special setup, with test stuff included in main project, then spring-core
must be added as well.
Regards,
Christoph
This Email was scanned by Sophos Anti Virus