Compare commits

..

2 Commits

Author SHA1 Message Date
Lukasz Lenart fbf98f6b19 Sets proper Maven version 2023-09-11 13:32:23 +02:00
Lukasz Lenart bb9869134d Always delete uploaded file 2023-09-11 13:26:28 +02:00
591 changed files with 1122 additions and 53676 deletions
+2 -4
View File
@@ -3,8 +3,8 @@ notifications:
commits: commits@struts.apache.org
# Send all issue emails (new, closed, comments) to issues@
issues: issues@struts.apache.org
# Send new/closed PR notifications to commits@
pullrequests_status: commits@struts.apache.org
# Send new/closed PR notifications to dev@
pullrequests_status: dev@struts.apache.org
# Send individual PR comments/reviews to issues@
pullrequests_comment: issues@struts.apache.org
# Link opened PRs with JIRA
@@ -16,5 +16,3 @@ github:
master: { }
autolink_jira:
- WW
dependabot_alerts: true
dependabot_updates: true
-10
View File
@@ -1,10 +0,0 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
+1 -1
View File
@@ -42,7 +42,7 @@ jobs:
language: [ 'java' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
+5 -5
View File
@@ -35,9 +35,9 @@ jobs:
java: [ '8', '11', '17' ]
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v3.0.2
- name: Set up cache
uses: actions/cache@v3.3.1
uses: actions/cache@v3.0.8
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
@@ -49,10 +49,10 @@ jobs:
distribution: adopt
java-version: ${{ matrix.java }}
- name: Build with Maven on Java ${{ matrix.java }}
if: matrix.java != '17'
run: mvn -B -V -DskipAssembly verify --no-transfer-progress
if: matrix.java != '11'
run: mvn -B -V -DskipAssembly test --no-transfer-progress
- name: Code coverage on Java ${{ matrix.java }}
if: matrix.java == '17'
if: matrix.java == '11'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
+3 -3
View File
@@ -40,12 +40,12 @@ jobs:
steps:
- name: "Checkout code"
uses: actions/checkout@v4 # 3.1.0
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # 3.1.0
with:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # 2.2.0
uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # 2.0.6
with:
results_file: results.sarif
results_format: sarif
@@ -57,7 +57,7 @@ jobs:
publish_results: true
- name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # 3.1.3
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # 3.1.0
with:
name: SARIF file
path: results.sarif
-2
View File
@@ -1,2 +0,0 @@
# Request PR review from any Apache Struts committer
* @apache/struts-committers
Vendored
+16 -15
View File
@@ -44,7 +44,7 @@ pipeline {
}
stage('Test') {
steps {
sh './mvnw -B verify -Pcoverage -DskipAssembly'
sh './mvnw -B test'
}
post {
always {
@@ -53,16 +53,6 @@ pipeline {
}
}
}
stage('Code Quality') {
when {
branch 'master'
}
steps {
withCredentials([string(credentialsId: 'asf-struts-sonarcloud', variable: 'SONARCLOUD_TOKEN')]) {
sh './mvnw -B -Pcoverage -DskipAssembly -Dsonar.login=${SONARCLOUD_TOKEN} verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar'
}
}
}
}
post {
always {
@@ -89,7 +79,7 @@ pipeline {
}
stage('Test') {
steps {
sh './mvnw -B test'
sh './mvnw -B verify -Pcoverage -DskipAssembly'
}
post {
always {
@@ -98,6 +88,16 @@ pipeline {
}
}
}
stage('Code Quality') {
when {
branch 'master'
}
steps {
withCredentials([string(credentialsId: 'asf-struts-sonarcloud', variable: 'SONARCLOUD_TOKEN')]) {
sh './mvnw -B -Pcoverage -DskipAssembly -Dsonar.login=${SONARCLOUD_TOKEN} verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar'
}
}
}
}
post {
always {
@@ -125,6 +125,7 @@ pipeline {
stage('Test') {
steps {
sh './mvnw -B test'
// step([$class: 'JiraIssueUpdater', issueSelector: [$class: 'DefaultIssueSelector'], scm: scm])
}
post {
always {
@@ -189,7 +190,7 @@ pipeline {
failure {
script {
emailext(
to: "commits@struts.apache.org",
to: "dev@struts.apache.org",
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
from: "Mr. Jenkins <jenkins@builds.apache.org>",
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} failed",
@@ -212,7 +213,7 @@ Director of Continuous Integration
unstable {
script {
emailext(
to: "commits@struts.apache.org",
to: "dev@struts.apache.org",
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
from: "Mr. Jenkins <jenkins@builds.apache.org>",
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} unstable",
@@ -235,7 +236,7 @@ Director of Continuous Integration
fixed {
script {
emailext(
to: "commits@struts.apache.org",
to: "dev@struts.apache.org",
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
from: 'Mr. Jenkins <jenkins@builds.apache.org>',
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} back to normal",
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-apps</artifactId>
<packaging>pom</packaging>
+4 -2
View File
@@ -24,12 +24,12 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-rest-showcase</artifactId>
<packaging>war</packaging>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
<name>Struts 2 Rest Showcase Webapp</name>
<description>Struts 2 Rest Showcase Example</description>
@@ -56,10 +56,12 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
+15 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-showcase</artifactId>
@@ -68,6 +68,12 @@
<artifactId>struts2-json-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
@@ -108,18 +114,22 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
@@ -130,6 +140,10 @@
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
+4 -3
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-assembly</artifactId>
@@ -41,8 +41,9 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>dependency-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>copy-war</id>
+5 -5
View File
@@ -24,12 +24,12 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<artifactId>struts-master</artifactId>
<version>14</version>
</parent>
<artifactId>struts2-bom</artifactId>
<version>6.3.0.1</version>
<version>6.2.0</version>
<packaging>pom</packaging>
<name>Struts 2 Bill of Materials</name>
@@ -44,7 +44,7 @@
</licenses>
<properties>
<struts-version.version>6.3.0.1</struts-version.version>
<struts-version.version>6.2.0</struts-version.version>
<maven.site.skip>true</maven.site.skip>
<maven.site.deploy.skip>true</maven.site.deploy.skip>
</properties>
@@ -190,7 +190,7 @@
</dependencyManagement>
<scm>
<tag>STRUTS_6_3_0_1</tag>
<tag>STRUTS_6_2_0</tag>
<connection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</developerConnection>
<url>https://github.com/apache/struts/</url>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-osgi-admin-bundle</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-osgi-bundles</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-osgi-demo-bundle</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-osgi-bundles</artifactId>
+2 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-core</artifactId>
<packaging>jar</packaging>
@@ -260,6 +260,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
@@ -22,17 +22,14 @@ import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.ConfigurationProvider;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.inject.Context;
import com.opensymphony.xwork2.inject.Factory;
import com.opensymphony.xwork2.inject.Scope;
import com.opensymphony.xwork2.inject.*;
import com.opensymphony.xwork2.test.StubConfigurationProvider;
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import junit.framework.TestCase;
import org.apache.commons.lang3.ClassUtils;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -217,8 +217,8 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
//block or allow access to properties
//see WW-2761 for more details
MemberAccessValueStack accessValueStack = (MemberAccessValueStack) newStack;
accessValueStack.useAcceptProperties(acceptedPatterns.getAcceptedPatterns());
accessValueStack.useExcludeProperties(excludedPatterns.getExcludedPatterns());
accessValueStack.setAcceptProperties(acceptedPatterns.getAcceptedPatterns());
accessValueStack.setExcludeProperties(excludedPatterns.getExcludedPatterns());
}
for (Map.Entry<String, Parameter> entry : acceptableParameters.entrySet()) {
@@ -24,6 +24,7 @@ import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
import com.opensymphony.xwork2.util.CompoundRoot;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.reflection.ReflectionException;
import ognl.ClassResolver;
import ognl.Ognl;
@@ -50,11 +51,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import static com.opensymphony.xwork2.util.TextParseUtil.commaDelimitedStringToSet;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.strip;
/**
@@ -100,8 +96,8 @@ public class OgnlUtil {
@Deprecated
public OgnlUtil() {
// Instantiate default Expression and BeanInfo caches (factories must be non-null).
this(new DefaultOgnlExpressionCacheFactory<>(),
new DefaultOgnlBeanInfoCacheFactory<>());
this(new DefaultOgnlExpressionCacheFactory<String, Object>(),
new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>());
}
/**
@@ -191,8 +187,9 @@ public class OgnlUtil {
}
private Set<Class<?>> parseClasses(String commaDelimitedClasses) {
Set<String> classNames = commaDelimitedStringToSet(commaDelimitedClasses);
Set<String> classNames = TextParseUtil.commaDelimitedStringToSet(commaDelimitedClasses);
Set<Class<?>> classes = new HashSet<>();
for (String className : classNames) {
try {
classes.add(Class.forName(className));
@@ -200,6 +197,7 @@ public class OgnlUtil {
throw new ConfigurationException("Cannot load class for exclusion/exemption configuration: " + className, e);
}
}
return classes;
}
@@ -220,13 +218,14 @@ public class OgnlUtil {
}
private Set<Pattern> parseExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) {
try {
return commaDelimitedStringToSet(commaDelimitedPackagePatterns)
.stream().map(Pattern::compile).collect(toSet());
} catch (PatternSyntaxException e) {
throw new ConfigurationException(
"Excluded package name patterns could not be parsed due to invalid regex: " + commaDelimitedPackagePatterns, e);
Set<String> packagePatterns = TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackagePatterns);
Set<Pattern> packageNamePatterns = new HashSet<>();
for (String pattern : packagePatterns) {
packageNamePatterns.add(Pattern.compile(pattern));
}
return packageNamePatterns;
}
@Inject(value = StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES, required = false)
@@ -262,12 +261,7 @@ public class OgnlUtil {
}
private Set<String> parseExcludedPackageNames(String commaDelimitedPackageNames) {
Set<String> parsedSet = commaDelimitedStringToSet(commaDelimitedPackageNames)
.stream().map(s -> strip(s, ".")).collect(toSet());
if (parsedSet.stream().anyMatch(s -> s.matches("(.*?)\\s(.*?)"))) {
throw new ConfigurationException("Excluded package names could not be parsed due to erroneous whitespace characters: " + commaDelimitedPackageNames);
}
return parsedSet;
return TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackageNames);
}
public Set<Class<?>> getExcludedClasses() {
@@ -878,22 +872,22 @@ public class OgnlUtil {
}
SecurityMemberAccess memberAccess = new SecurityMemberAccess(allowStaticFieldAccess);
memberAccess.disallowProxyMemberAccess(disallowProxyMemberAccess);
memberAccess.setDisallowProxyMemberAccess(disallowProxyMemberAccess);
if (devMode) {
if (!warnReported.get()) {
warnReported.set(true);
LOG.warn("Working in devMode, using devMode excluded classes and packages!");
}
memberAccess.useExcludedClasses(devModeExcludedClasses);
memberAccess.useExcludedPackageNamePatterns(devModeExcludedPackageNamePatterns);
memberAccess.useExcludedPackageNames(devModeExcludedPackageNames);
memberAccess.useExcludedPackageExemptClasses(devModeExcludedPackageExemptClasses);
memberAccess.setExcludedClasses(devModeExcludedClasses);
memberAccess.setExcludedPackageNamePatterns(devModeExcludedPackageNamePatterns);
memberAccess.setExcludedPackageNames(devModeExcludedPackageNames);
memberAccess.setExcludedPackageExemptClasses(devModeExcludedPackageExemptClasses);
} else {
memberAccess.useExcludedClasses(excludedClasses);
memberAccess.useExcludedPackageNamePatterns(excludedPackageNamePatterns);
memberAccess.useExcludedPackageNames(excludedPackageNames);
memberAccess.useExcludedPackageExemptClasses(excludedPackageExemptClasses);
memberAccess.setExcludedClasses(excludedClasses);
memberAccess.setExcludedPackageNamePatterns(excludedPackageNamePatterns);
memberAccess.setExcludedPackageNames(excludedPackageNames);
memberAccess.setExcludedPackageExemptClasses(excludedPackageExemptClasses);
}
return Ognl.createDefaultContext(root, memberAccess, resolver, defaultConverter);
@@ -89,11 +89,11 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
@Inject
protected void setOgnlUtil(OgnlUtil ognlUtil) {
this.ognlUtil = ognlUtil;
securityMemberAccess.useExcludedClasses(ognlUtil.getExcludedClasses());
securityMemberAccess.useExcludedPackageNamePatterns(ognlUtil.getExcludedPackageNamePatterns());
securityMemberAccess.useExcludedPackageNames(ognlUtil.getExcludedPackageNames());
securityMemberAccess.useExcludedPackageExemptClasses(ognlUtil.getExcludedPackageExemptClasses());
securityMemberAccess.disallowProxyMemberAccess(ognlUtil.isDisallowProxyMemberAccess());
securityMemberAccess.setExcludedClasses(ognlUtil.getExcludedClasses());
securityMemberAccess.setExcludedPackageNamePatterns(ognlUtil.getExcludedPackageNamePatterns());
securityMemberAccess.setExcludedPackageNames(ognlUtil.getExcludedPackageNames());
securityMemberAccess.setExcludedPackageExemptClasses(ognlUtil.getExcludedPackageExemptClasses());
securityMemberAccess.setDisallowProxyMemberAccess(ognlUtil.isDisallowProxyMemberAccess());
}
protected void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot, boolean allowStaticFieldAccess) {
@@ -482,22 +482,12 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
((OgnlContext) context).getValues().clear();
}
@Deprecated
public void setAcceptProperties(Set<Pattern> acceptedProperties) {
securityMemberAccess.useAcceptProperties(acceptedProperties);
securityMemberAccess.setAcceptProperties(acceptedProperties);
}
public void useAcceptProperties(Set<Pattern> acceptedProperties) {
securityMemberAccess.useAcceptProperties(acceptedProperties);
}
@Deprecated
public void setExcludeProperties(Set<Pattern> excludeProperties) {
securityMemberAccess.useExcludeProperties(excludeProperties);
}
public void useExcludeProperties(Set<Pattern> excludeProperties) {
securityMemberAccess.useExcludeProperties(excludeProperties);
securityMemberAccess.setExcludeProperties(excludeProperties);
}
@Inject
@@ -27,17 +27,13 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
/**
* Allows access decisions to be made on the basis of whether a member is static or not.
* Also blocks or allows access to properties.
@@ -47,12 +43,12 @@ public class SecurityMemberAccess implements MemberAccess {
private static final Logger LOG = LogManager.getLogger(SecurityMemberAccess.class);
private final boolean allowStaticFieldAccess;
private Set<Pattern> excludeProperties = emptySet();
private Set<Pattern> acceptProperties = emptySet();
private Set<Class<?>> excludedClasses = emptySet();
private Set<Pattern> excludedPackageNamePatterns = emptySet();
private Set<String> excludedPackageNames = emptySet();
private Set<Class<?>> excludedPackageExemptClasses = emptySet();
private Set<Pattern> excludeProperties = Collections.emptySet();
private Set<Pattern> acceptProperties = Collections.emptySet();
private Set<Class<?>> excludedClasses = Collections.emptySet();
private Set<Pattern> excludedPackageNamePatterns = Collections.emptySet();
private Set<String> excludedPackageNames = Collections.emptySet();
private Set<Class<?>> excludedPackageExemptClasses = Collections.emptySet();
private boolean disallowProxyMemberAccess;
/**
@@ -64,7 +60,6 @@ public class SecurityMemberAccess implements MemberAccess {
*/
public SecurityMemberAccess(boolean allowStaticFieldAccess) {
this.allowStaticFieldAccess = allowStaticFieldAccess;
useExcludedClasses(excludedClasses); // Initialise default exclusions
}
@Override
@@ -242,15 +237,18 @@ public class SecurityMemberAccess implements MemberAccess {
protected boolean isExcludedPackageNamePatterns(Class<?> clazz) {
String packageName = toPackageName(clazz);
return excludedPackageNamePatterns.stream().anyMatch(pattern -> pattern.matcher(packageName).matches());
for (Pattern pattern : excludedPackageNamePatterns) {
if (pattern.matcher(packageName).matches()) {
return true;
}
}
return false;
}
protected boolean isExcludedPackageNames(Class<?> clazz) {
String packageName = toPackageName(clazz);
List<String> packageParts = Arrays.asList(packageName.split("\\."));
for (int i = 0; i < packageParts.size(); i++) {
String parentPackage = String.join(".", packageParts.subList(0, i + 1));
if (excludedPackageNames.contains(parentPackage)) {
String suffixedPackageName = toPackageName(clazz) + ".";
for (String excludedPackageName : excludedPackageNames) {
if (suffixedPackageName.startsWith(excludedPackageName)) {
return true;
}
}
@@ -258,11 +256,14 @@ public class SecurityMemberAccess implements MemberAccess {
}
protected boolean isClassExcluded(Class<?> clazz) {
return excludedClasses.contains(clazz);
if (clazz == Object.class || (clazz == Class.class && !allowStaticFieldAccess)) {
return true;
}
return excludedClasses.stream().anyMatch(clazz::isAssignableFrom);
}
protected boolean isExcludedPackageExempt(Class<?> clazz) {
return excludedPackageExemptClasses.contains(clazz);
return excludedPackageExemptClasses.stream().anyMatch(clazz::equals);
}
protected boolean isAcceptableProperty(String name) {
@@ -298,92 +299,31 @@ public class SecurityMemberAccess implements MemberAccess {
return false;
}
/**
* @deprecated please use {@link #useExcludeProperties(Set)}
*/
@Deprecated
public void setExcludeProperties(Set<Pattern> excludeProperties) {
this.excludeProperties = excludeProperties;
}
public void useExcludeProperties(Set<Pattern> excludeProperties) {
this.excludeProperties = excludeProperties;
}
/**
* @deprecated please use {@link #useAcceptProperties(Set)}
*/
@Deprecated
public void setAcceptProperties(Set<Pattern> acceptedProperties) {
this.acceptProperties = acceptedProperties;
}
public void useAcceptProperties(Set<Pattern> acceptedProperties) {
this.acceptProperties = acceptedProperties;
}
/**
* @deprecated please use {@link #useExcludedClasses(Set)}
*/
@Deprecated
public void setExcludedClasses(Set<Class<?>> excludedClasses) {
useExcludedClasses(excludedClasses);
this.excludedClasses = excludedClasses;
}
public void useExcludedClasses(Set<Class<?>> excludedClasses) {
Set<Class<?>> newExcludedClasses = new HashSet<>(excludedClasses);
newExcludedClasses.add(Object.class);
if (!allowStaticFieldAccess) {
newExcludedClasses.add(Class.class);
}
this.excludedClasses = unmodifiableSet(newExcludedClasses);
}
/**
* @deprecated please use {@link #useExcludedPackageNamePatterns(Set)}
*/
@Deprecated
public void setExcludedPackageNamePatterns(Set<Pattern> excludedPackageNamePatterns) {
this.excludedPackageNamePatterns = excludedPackageNamePatterns;
}
public void useExcludedPackageNamePatterns(Set<Pattern> excludedPackageNamePatterns) {
this.excludedPackageNamePatterns = excludedPackageNamePatterns;
}
/**
* @deprecated please use {@link #useExcludedPackageNames(Set)}
*/
@Deprecated
public void setExcludedPackageNames(Set<String> excludedPackageNames) {
this.excludedPackageNames = excludedPackageNames;
}
public void useExcludedPackageNames(Set<String> excludedPackageNames) {
this.excludedPackageNames = excludedPackageNames;
}
/**
* @deprecated please use {@link #useExcludedPackageExemptClasses(Set)}
*/
@Deprecated
public void setExcludedPackageExemptClasses(Set<Class<?>> excludedPackageExemptClasses) {
this.excludedPackageExemptClasses = excludedPackageExemptClasses;
}
public void useExcludedPackageExemptClasses(Set<Class<?>> excludedPackageExemptClasses) {
this.excludedPackageExemptClasses = excludedPackageExemptClasses;
}
/**
* @deprecated please use {@link #disallowProxyMemberAccess(boolean)}
*/
@Deprecated
public void setDisallowProxyMemberAccess(boolean disallowProxyMemberAccess) {
this.disallowProxyMemberAccess = disallowProxyMemberAccess;
}
public void disallowProxyMemberAccess(boolean disallowProxyMemberAccess) {
this.disallowProxyMemberAccess = disallowProxyMemberAccess;
}
}
@@ -27,20 +27,8 @@ import java.util.regex.Pattern;
*/
public interface MemberAccessValueStack {
/**
* @deprecated please use {@link #useExcludeProperties(Set)}
*/
@Deprecated
void setExcludeProperties(Set<Pattern> excludeProperties);
void useExcludeProperties(Set<Pattern> excludeProperties);
/**
* @deprecated please use {@link #useAcceptProperties(Set)}
*/
@Deprecated
void setAcceptProperties(Set<Pattern> acceptedProperties);
void useAcceptProperties(Set<Pattern> acceptedProperties);
}
@@ -20,12 +20,9 @@ package com.opensymphony.xwork2.util;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
import com.opensymphony.xwork2.inject.Container;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.*;
/**
@@ -244,13 +241,13 @@ public class TextParseUtil {
/**
* Tests if given string is not null and not empty when excluding of empty
* elements is requested.
*
*
* @param str String to check.
* @param excludeEmptyElements Whether empty elements shall be excluded.
* @return True if given string can be included in collection.
*/
private static boolean shallBeIncluded(String str, boolean excludeEmptyElements) {
return !excludeEmptyElements || str != null && !str.isEmpty();
return !excludeEmptyElements || ((str != null) && (str.length() > 0));
}
/**
@@ -259,7 +256,14 @@ public class TextParseUtil {
* @return A set from comma delimited Strings.
*/
public static Set<String> commaDelimitedStringToSet(String s) {
return Arrays.stream(s.split(",")).map(String::trim).filter(s1 -> !s1.isEmpty()).collect(Collectors.toSet());
Set<String> set = new HashSet<>();
String[] split = s.split(",");
for (String aSplit : split) {
String trimmed = aSplit.trim();
if (trimmed.length() > 0)
set.add(trimmed);
}
return set;
}
@@ -283,7 +287,7 @@ public class TextParseUtil {
*
* @author tm_jee
*/
public interface ParsedValueEvaluator {
public static interface ParsedValueEvaluator {
/**
* Evaluated the value parsed by Ognl value stack.
@@ -36,9 +36,10 @@ public class ApplicationMap extends AbstractMap<String, Object> implements Seria
private static final long serialVersionUID = 9136809763083228202L;
private final ServletContext context;
private ServletContext context;
private Set<Entry<String, Object>> entries;
/**
* Creates a new map object given the servlet context.
*
@@ -116,16 +117,12 @@ public class ApplicationMap extends AbstractMap<String, Object> implements Seria
* @param key the entry key.
* @return the servlet context attribute or init parameter or <tt>null</tt> if the entry is not found.
*/
@Override
public Object get(final Object key) {
if (key == null) {
return null;
}
public Object get(final String key) {
// Try context attributes first, then init params
// This gives the proper shadowing effects
Object value = context.getAttribute(key.toString());
Object value = context.getAttribute(key);
return (value == null) ? context.getInitParameter(key.toString()) : value;
return (value == null) ? context.getInitParameter(key) : value;
}
/**
@@ -94,12 +94,8 @@ public class RequestMap extends AbstractMap<String, Object> implements Serializa
* @param key the name of the request attribute.
* @return the request attribute or <tt>null</tt> if it doesn't exist.
*/
@Override
public Object get(final Object key) {
if (key == null) {
return null;
}
return request.getAttribute(key.toString());
public Object get(final String key) {
return request.getAttribute(key);
}
/**
@@ -47,7 +47,7 @@ import java.io.OutputStream;
* <li><b>bufferSize</b> - the size of the buffer to copy from input to output
* (default = <code>1024</code>).</li>
* <li><b>allowCaching</b> if set to 'false' it will set the headers 'Pragma' and 'Cache-Control'
* to 'no-cache', and prevent client from caching the content. (default = <code>true</code>)
* to 'no-cahce', and prevent client from caching the content. (default = <code>true</code>)
* <li><b>contentCharSet</b> if set to a string, ';charset=value' will be added to the
* content-type header, where value is the string set. If set to an expression, the result
* of evaluating the expression will be used. If not set, then no charset will be set on
@@ -18,16 +18,14 @@
*/
package org.apache.struts2.util;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
import ognl.OgnlException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsException;
import org.apache.struts2.views.jsp.ui.OgnlTool;
import org.apache.struts2.views.util.UrlHelper;
import javax.servlet.RequestDispatcher;
@@ -41,16 +39,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.text.MessageFormat.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import java.util.*;
/**
* Struts base utility class, for use in Velocity and Freemarker templates
@@ -61,30 +50,32 @@ public class StrutsUtil {
protected HttpServletRequest request;
protected HttpServletResponse response;
protected Map<String, Class<?>> classes = new HashMap<>();
protected OgnlUtil ognl;
protected Map<String, Class> classes = new Hashtable<>();
protected OgnlTool ognl;
protected ValueStack stack;
private final UrlHelper urlHelper;
private final ObjectFactory objectFactory;
private UrlHelper urlHelper;
private ObjectFactory objectFactory;
public StrutsUtil(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
this.stack = stack;
this.request = request;
this.response = response;
this.ognl = stack.getActionContext().getContainer().getInstance(OgnlUtil.class);
this.ognl = stack.getActionContext().getContainer().getInstance(OgnlTool.class);
this.urlHelper = stack.getActionContext().getContainer().getInstance(UrlHelper.class);
this.objectFactory = stack.getActionContext().getContainer().getInstance(ObjectFactory.class);
}
public Object bean(Object name) throws Exception {
String className = name.toString();
Class<?> clazz = classes.get(className);
if (clazz == null) {
clazz = ClassLoaderUtil.loadClass(className, StrutsUtil.class);
classes.put(className, clazz);
public Object bean(Object aName) throws Exception {
String name = aName.toString();
Class c = classes.get(name);
if (c == null) {
c = ClassLoaderUtil.loadClass(name, StrutsUtil.class);
classes.put(name, c);
}
return objectFactory.buildBean(clazz, stack.getContext());
return objectFactory.buildBean(c, stack.getContext());
}
public boolean isTrue(String expression) {
@@ -97,20 +88,30 @@ public class StrutsUtil {
}
public String include(Object aName) throws Exception {
RequestDispatcher dispatcher = request.getRequestDispatcher(aName.toString());
if (dispatcher == null) {
throw new IllegalArgumentException("Cannot find included file " + aName);
try {
RequestDispatcher dispatcher = request.getRequestDispatcher(aName.toString());
if (dispatcher == null) {
throw new IllegalArgumentException("Cannot find included file " + aName);
}
ResponseWrapper responseWrapper = new ResponseWrapper(response);
dispatcher.include(request, responseWrapper);
return responseWrapper.getData();
}
catch (Exception e) {
LOG.debug("Cannot include {}", aName, e);
throw e;
}
ResponseWrapper responseWrapper = new ResponseWrapper(response);
dispatcher.include(request, responseWrapper);
return responseWrapper.getData();
}
public String urlEncode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.debug(format("Cannot encode URL [{0}]", s), e);
LOG.debug("Cannot encode URL [{}]", s, e);
return s;
}
}
@@ -123,17 +124,6 @@ public class StrutsUtil {
return stack.findValue(expression, Class.forName(className));
}
public Object findValue(String expr, Object context) {
try {
return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context);
} catch (OgnlException e) {
if (e.getReason() instanceof SecurityException) {
LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e);
}
return null;
}
}
public String getText(String text) {
return (String) stack.findValue("getText('" + text.replace('\'', '"') + "')");
}
@@ -142,7 +132,7 @@ public class StrutsUtil {
* @return the url ContextPath. An empty string if one does not exist.
*/
public String getContext() {
return request == null ? "" : request.getContextPath();
return (request == null)? "" : request.getContextPath();
}
public String translateVariables(String expression) {
@@ -166,64 +156,71 @@ public class StrutsUtil {
* to use as the value of the ListEntry
* @return a List of ListEntry
*/
public List<ListEntry> makeSelectList(String selectedList, String list, String listKey, String listValue) {
List<ListEntry> selectList = new ArrayList<>();
public List makeSelectList(String selectedList, String list, String listKey, String listValue) {
List selectList = new ArrayList();
Collection items = (Collection) stack.findValue(list);
if (items == null) {
return selectList;
Collection selectedItems = null;
Object i = stack.findValue(selectedList);
if (i != null) {
if (i.getClass().isArray()) {
selectedItems = Arrays.asList((Object[]) i);
} else if (i instanceof Collection) {
selectedItems = (Collection) i;
} else {
// treat it is a single item
selectedItems = new ArrayList();
selectedItems.add(i);
}
}
Collection selectedItems = getSelectedItems(selectedList);
for (Object element : items) {
Object key = computeKey(listKey, element);
Object value = computeValue(listValue, element);
boolean isSelected = value != null && selectedItems.contains(value);
selectList.add(new ListEntry(key, value, isSelected));
Collection items = (Collection) stack.findValue(list);
if (items != null) {
for (Object element : items) {
Object key;
if ((listKey == null) || (listKey.length() == 0)) {
key = element;
} else {
key = ognl.findValue(listKey, element);
}
Object value = null;
if ((listValue == null) || (listValue.length() == 0)) {
value = element;
} else {
value = ognl.findValue(listValue, element);
}
boolean isSelected = false;
if ((value != null) && (selectedItems != null) && selectedItems.contains(value)) {
isSelected = true;
}
selectList.add(new ListEntry(key, value, isSelected));
}
}
return selectList;
}
private Collection getSelectedItems(String selectedListName) {
Object i = stack.findValue(selectedListName);
if (i == null) {
return emptyList();
}
if (i.getClass().isArray()) {
return Arrays.asList((Object[]) i);
} else if (i instanceof Collection) {
return (Collection) i;
}
return singletonList(i);
}
private Object computeKey(String listKey, Object element) {
if (listKey == null || listKey.isEmpty()) {
return element;
}
return findValue(listKey, element);
}
private Object computeValue(String listValue, Object element) {
if (listValue == null || listValue.isEmpty()) {
return element;
}
return findValue(listValue, element);
}
public int toInt(long aLong) {
return (int) aLong;
}
public long toLong(int anInt) {
return anInt;
return (long) anInt;
}
public long toLong(String aLong) {
if (aLong == null || aLong.isEmpty()) {
if (aLong == null) {
return 0;
}
return Long.parseLong(aLong);
}
@@ -236,7 +233,14 @@ public class StrutsUtil {
}
public String toStringSafe(Object obj) {
return obj == null ? "" : obj.toString();
try {
if (obj != null) {
return String.valueOf(obj);
}
return "";
} catch (Exception e) {
return "Exception thrown: " + e;
}
}
static class ResponseWrapper extends HttpServletResponseWrapper {
@@ -253,6 +257,7 @@ public class StrutsUtil {
public String getData() {
writer.flush();
return strout.toString();
}
@@ -24,24 +24,16 @@ import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.ValueStack;
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.cache.WebappTemplateLoader;
import freemarker.cache.*;
import freemarker.core.HTMLOutputFormat;
import freemarker.core.OutputFormat;
import freemarker.core.TemplateClassResolver;
import freemarker.ext.jsp.TaglibFactory;
import freemarker.ext.servlet.HttpRequestHashModel;
import freemarker.ext.servlet.HttpRequestParametersHashModel;
import freemarker.ext.servlet.HttpSessionHashModel;
import freemarker.ext.servlet.ServletContextHashModel;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import freemarker.template.TemplateModel;
import freemarker.template.Version;
import freemarker.template.*;
import freemarker.template.utility.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -59,13 +51,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.*;
/**
* <p>
@@ -190,27 +176,27 @@ public class FreemarkerManager {
public void setEncoding(String encoding) {
this.encoding = encoding;
}
@Inject(StrutsConstants.STRUTS_FREEMARKER_WRAPPER_ALT_MAP)
public void setWrapperAltMap(String val) {
altMapWrapper = "true".equals(val);
}
@Inject(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE)
public void setCacheBeanWrapper(String val) {
cacheBeanWrapper = "true".equals(val);
}
@Inject(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE)
public void setMruMaxStrongSize(String size) {
mruMaxStrongSize = Integer.parseInt(size);
}
@Inject(value = StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, required = false)
public void setTemplateUpdateDelay(String delay) {
templateUpdateDelay = delay;
}
@Inject
public void setContainer(Container container) {
Map<String, TagLibraryModelProvider> map = new HashMap<>();
@@ -295,8 +281,8 @@ public class FreemarkerManager {
loadSettings(servletContext);
}
/**
* Sets the Freemarker Configuration's template loader with the FreemarkerThemeTemplateLoader
/**
* Sets the Freemarker Configuration's template loader with the FreemarkerThemeTemplateLoader
* at the top.
*
* @param templateLoader the template loader
@@ -307,7 +293,7 @@ public class FreemarkerManager {
themeTemplateLoader.init(templateLoader);
config.setTemplateLoader(themeTemplateLoader);
}
/**
* Create the instance of the freemarker Configuration object.
* <p>
@@ -557,7 +543,7 @@ public class FreemarkerManager {
protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response) {
// put the same objects into the context that the velocity result uses
Map<String, Object> standard = ContextUtil.getStandardContext(stack, request, response);
Map standard = ContextUtil.getStandardContext(stack, request, response);
model.putAll(standard);
// support for JSP exception pages, exposing the servlet or JSP exception
@@ -45,9 +45,11 @@ public class TagUtils {
"Please read https://struts.apache.org/security/#never-expose-jsp-files-directly");
} else {
LOG.trace("Adds the current PageContext to ActionContext");
AttributeMap attrMap = new AttributeMap(stack.getContext());
stack.getActionContext()
.withPageContext(pageContext)
.with("attr", new AttributeMap(stack.getContext()));
.with("attr", attrMap);
}
return stack;
@@ -19,16 +19,16 @@
package org.apache.struts2.views.jsp.ui;
import com.opensymphony.xwork2.ActionContext;
import ognl.OgnlException;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.ognl.OgnlUtil;
import ognl.OgnlException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil} instead.
* FIXME: remove?
*/
@Deprecated
public class OgnlTool {
private static final Logger LOG = LogManager.getLogger(OgnlTool.class);
@@ -43,10 +43,6 @@ public class OgnlTool {
this.ognlUtil = ognlUtil;
}
/**
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil#findValue(String, Object)} instead.
*/
@Deprecated
public Object findValue(String expr, Object context) {
try {
return ognlUtil.getValue(expr, ActionContext.getContext().getContextMap(), context);
@@ -18,9 +18,12 @@
*/
package org.apache.struts2.views.util;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.util.StrutsUtil;
import org.apache.struts2.views.jsp.ui.OgnlTool;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -47,9 +50,8 @@ public class ContextUtil {
map.put(SESSION, req.getSession(false));
map.put(BASE, req.getContextPath());
map.put(STACK, stack);
StrutsUtil util = new StrutsUtil(stack, req, res);
map.put(STRUTS, util);
map.put(OGNL, util); // Deprecated since 6.3.0
map.put(OGNL, stack.getActionContext().getContainer().getInstance(OgnlTool.class));
map.put(STRUTS, new StrutsUtil(stack, req, res));
ActionInvocation invocation = stack.getActionContext().getActionInvocation();
if (invocation != null) {
-1
View File
@@ -198,7 +198,6 @@
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>
<!-- Deprecated since 6.3.0, inject OgnlUtil directly instead, or use StrutsUtil -->
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/>
<bean type="org.apache.struts2.dispatcher.StaticContentLoader"
@@ -2,19 +2,19 @@
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -55,52 +55,52 @@
<!-- constant name="struts.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^(?!javax\.servlet\..+)(javax\..+)" / -->
<!-- constant name="struts.devMode.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^(?!javax\.servlet\..+)(javax\..+)" / -->
<!-- All classes within the following packages and their sub-packages are excluded -->
<!-- this is simpler version of the above used with string comparison -->
<constant name="struts.excludedPackageNames"
value="
ognl,
java.io,
java.net,
java.nio,
javax,
freemarker.core,
freemarker.template,
freemarker.ext.jsp,
freemarker.ext.rhino,
sun.misc,
sun.reflect,
javassist,
org.apache.velocity,
org.objectweb.asm,
org.springframework.context,
com.opensymphony.xwork2.inject,
com.opensymphony.xwork2.ognl,
com.opensymphony.xwork2.security,
com.opensymphony.xwork2.util,
org.apache.tomcat,
org.apache.catalina.core,
org.wildfly.extension.undertow.deployment"/>
ognl.,
java.io.,
java.net.,
java.nio.,
javax.,
freemarker.core.,
freemarker.template.,
freemarker.ext.jsp.,
freemarker.ext.rhino.,
sun.misc.,
sun.reflect.,
javassist.,
org.apache.velocity.,
org.objectweb.asm.,
org.springframework.context.,
com.opensymphony.xwork2.inject.,
com.opensymphony.xwork2.ognl.,
com.opensymphony.xwork2.security.,
com.opensymphony.xwork2.util.,
org.apache.tomcat.,
org.apache.catalina.core.,
org.wildfly.extension.undertow.deployment."/>
<constant name="struts.devMode.excludedPackageNames"
value="
ognl,
java.io,
java.net,
java.nio,
javax,
freemarker.core,
freemarker.template,
freemarker.ext.jsp,
freemarker.ext.rhino,
sun.misc,
sun.reflect,
javassist,
org.apache.velocity,
org.objectweb.asm,
org.springframework.context,
com.opensymphony.xwork2.inject,
com.opensymphony.xwork2.ognl,
com.opensymphony.xwork2.security,
com.opensymphony.xwork2.util"/>
ognl.,
java.io.,
java.net.,
java.nio.,
javax.,
freemarker.core.,
freemarker.template.,
freemarker.ext.jsp.,
freemarker.ext.rhino.,
sun.misc.,
sun.reflect.,
javassist.,
org.apache.velocity.,
org.objectweb.asm.,
org.springframework.context.,
com.opensymphony.xwork2.inject.,
com.opensymphony.xwork2.ognl.,
com.opensymphony.xwork2.security.,
com.opensymphony.xwork2.util."/>
</struts>
+1 -1
View File
@@ -33,5 +33,5 @@
#end
#macro(property $object $property)
$!{struts.findValue($property, $object)}
$!{ognl.findValue($property, $object)}
#end
@@ -35,6 +35,7 @@ import com.opensymphony.xwork2.util.Owner;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import java.beans.BeanInfo;
import ognl.InappropriateExpressionException;
import ognl.MethodFailedException;
import ognl.NoSuchPropertyException;
@@ -47,7 +48,6 @@ import ognl.SimpleNode;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.lang.reflect.Method;
import java.text.DateFormat;
@@ -64,8 +64,6 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import static org.junit.Assert.assertThrows;
public class OgnlUtilTest extends XWorkTestCase {
// Fields for static field access test
@@ -879,33 +877,6 @@ public class OgnlUtilTest extends XWorkTestCase {
assertEquals(123, foo.getALong());
}
public void testBeanMapExpressions() throws OgnlException, NoSuchMethodException {
Foo foo = new Foo();
ognlUtil.setExcludedPackageNames(
"com.opensymphony.xwork2.ognl."
);
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
String expression = "%{\n" +
"(#request.a=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.a.setBean(#request.get('struts.valueStack')) == true) +\n" +
"(#request.b=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.b.setBean(#request.get('a').get('context'))) +\n" +
"(#request.c=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.c.setBean(#request.get('b').get('memberAccess'))) +\n" +
"(#request.get('c').put('excluded'+'PackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet())) +\n" +
"(#request.get('c').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()))\n" +
"}";
ognlUtil.setValue("title", context, foo, expression);
assertEquals(foo.getTitle(), expression);
SecurityMemberAccess sma = (SecurityMemberAccess) ((OgnlContext) context).getMemberAccess();
assertFalse(sma.isAccessible(context, sma, sma.getClass().getDeclaredMethod("setExcludedClasses", Set.class), "excludedClasses"));
}
public void testNullProperties() {
Foo foo = new Foo();
foo.setALong(88);
@@ -1714,13 +1685,6 @@ public class OgnlUtilTest extends XWorkTestCase {
assertSame(that, root);
}
public void testSetExcludedPackageNames() {
assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang\njava.awt"));
assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang\tjava.awt"));
ConfigurationException e = assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang java.awt"));
assertTrue(e.getMessage().contains("erroneous whitespace characters"));
}
public void testGetExcludedPackageNames() {
// Getter should return an immutable collection
OgnlUtil util = new OgnlUtil();
@@ -1737,7 +1701,7 @@ public class OgnlUtilTest extends XWorkTestCase {
public void testGetExcludedPackageNamesAlternateConstructorPopulated() {
// Getter should return an immutable collection
OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), new DefaultOgnlBeanInfoCacheFactory<>());
OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>());
util.setExcludedPackageNames("java.lang,java.awt");
assertEquals(util.getExcludedPackageNames().size(), 2);
try {
@@ -1870,19 +1834,19 @@ public class OgnlUtilTest extends XWorkTestCase {
defaultOgnlCacheFactory.setUseLRUCache("false");
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit());
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit() );
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(6, 6, 0.75f, false);
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit());
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit() );
// LRU cache
defaultOgnlCacheFactory.setCacheMaxSize("30");
defaultOgnlCacheFactory.setUseLRUCache("true");
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit());
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit() );
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(15, 15, 0.75f, false);
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit());
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit() );
}
/**
@@ -75,7 +75,7 @@ public class SecurityMemberAccessTest {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FooBar.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -118,7 +118,7 @@ public class SecurityMemberAccessTest {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(BarInterface.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -135,7 +135,7 @@ public class SecurityMemberAccessTest {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(BarInterface.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -152,7 +152,7 @@ public class SecurityMemberAccessTest {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(BarInterface.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -169,7 +169,7 @@ public class SecurityMemberAccessTest {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FooInterface.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
@@ -178,12 +178,29 @@ public class SecurityMemberAccessTest {
assertTrue("barLogic() from BarInterface isn't accessible!!!", accessible);
}
@Test
public void testMiddleOfInheritanceExclusion4() throws Exception {
// given
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
Set<Class<?>> excluded = new HashSet<>();
excluded.add(FooBarInterface.class);
sma.setExcludedClasses(excluded);
// when
boolean accessible = sma.isAccessible(context, target, member, propertyName);
// then
assertFalse("barLogic() from BarInterface is accessible!!!", accessible);
}
@Test
public void testPackageExclusion() throws Exception {
// given
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
String propertyName = "stringField";
Member member = FooBar.class.getMethod(formGetterName(propertyName));
@@ -200,11 +217,11 @@ public class SecurityMemberAccessTest {
// given
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
Set<Class<?>> allowed = new HashSet<>();
allowed.add(FooBar.class);
sma.useExcludedPackageExemptClasses(allowed);
sma.setExcludedPackageExemptClasses(allowed);
String propertyName = "stringField";
Member member = FooBar.class.getMethod(formGetterName(propertyName));
@@ -221,7 +238,7 @@ public class SecurityMemberAccessTest {
// given
Set<String> excluded = new HashSet<>();
excluded.add(FooBar.class.getPackage().getName());
sma.useExcludedPackageNames(excluded);
sma.setExcludedPackageNames(excluded);
String propertyName = "stringField";
Member member = FooBar.class.getMethod(formGetterName(propertyName));
@@ -238,11 +255,11 @@ public class SecurityMemberAccessTest {
// given
Set<String> excluded = new HashSet<>();
excluded.add(FooBar.class.getPackage().getName());
sma.useExcludedPackageNames(excluded);
sma.setExcludedPackageNames(excluded);
Set<Class<?>> allowed = new HashSet<>();
allowed.add(FooBar.class);
sma.useExcludedPackageExemptClasses(allowed);
sma.setExcludedPackageExemptClasses(allowed);
String propertyName = "stringField";
Member member = FooBar.class.getMethod(formGetterName(propertyName));
@@ -259,12 +276,12 @@ public class SecurityMemberAccessTest {
// given
Set<String> excluded = new HashSet<>();
excluded.add(FooBar.class.getPackage().getName());
sma.useExcludedPackageNames(excluded);
sma.setExcludedPackageNames(excluded);
// Exemption must exist for both classes (target and member) if they both match a banned package
Set<Class<?>> allowed = new HashSet<>();
allowed.add(BarInterface.class);
sma.useExcludedPackageExemptClasses(allowed);
sma.setExcludedPackageExemptClasses(allowed);
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
@@ -281,13 +298,13 @@ public class SecurityMemberAccessTest {
// given
Set<String> excluded = new HashSet<>();
excluded.add(FooBar.class.getPackage().getName());
sma.useExcludedPackageNames(excluded);
sma.setExcludedPackageNames(excluded);
// Exemption must exist for both classes (target and member) if they both match a banned package
Set<Class<?>> allowed = new HashSet<>();
allowed.add(BarInterface.class);
allowed.add(FooBar.class);
sma.useExcludedPackageExemptClasses(allowed);
sma.setExcludedPackageExemptClasses(allowed);
String propertyName = "barLogic";
Member member = BarInterface.class.getMethod(propertyName);
@@ -304,7 +321,7 @@ public class SecurityMemberAccessTest {
// given
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
Class<?> clazz = Class.forName("PackagelessAction");
@@ -320,7 +337,7 @@ public class SecurityMemberAccessTest {
// given
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^$"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
Class<?> clazz = Class.forName("PackagelessAction");
@@ -344,7 +361,7 @@ public class SecurityMemberAccessTest {
@Test
public void testAccessStaticMethod() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getMethod("sayHello");
@@ -357,7 +374,7 @@ public class SecurityMemberAccessTest {
@Test
public void testAccessStaticField() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getField("MAX_VALUE");
@@ -371,7 +388,7 @@ public class SecurityMemberAccessTest {
public void testBlockedStaticFieldWhenFlagIsTrue() throws Exception {
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getField("MAX_VALUE");
@@ -383,7 +400,7 @@ public class SecurityMemberAccessTest {
// public static final test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.class.getField("MIN_VALUE");
@@ -395,7 +412,7 @@ public class SecurityMemberAccessTest {
// package static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PACKAGE_STRING");
@@ -407,7 +424,7 @@ public class SecurityMemberAccessTest {
// package final static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PACKAGE_STRING");
@@ -419,7 +436,7 @@ public class SecurityMemberAccessTest {
// protected static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PROTECTED_STRING");
@@ -431,7 +448,7 @@ public class SecurityMemberAccessTest {
// protected final static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PROTECTED_STRING");
@@ -443,7 +460,7 @@ public class SecurityMemberAccessTest {
// private static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PRIVATE_STRING");
@@ -455,7 +472,7 @@ public class SecurityMemberAccessTest {
// private final static test
// given
assignNewSma(true);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PRIVATE_STRING");
@@ -469,7 +486,7 @@ public class SecurityMemberAccessTest {
public void testBlockedStaticFieldWhenFlagIsFalse() throws Exception {
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getField("MAX_VALUE");
@@ -481,7 +498,7 @@ public class SecurityMemberAccessTest {
// public static final test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.class.getField("MIN_VALUE");
@@ -493,7 +510,7 @@ public class SecurityMemberAccessTest {
// package static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PACKAGE_STRING");
@@ -505,7 +522,7 @@ public class SecurityMemberAccessTest {
// package final static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PACKAGE_STRING");
@@ -517,7 +534,7 @@ public class SecurityMemberAccessTest {
// protected static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PROTECTED_STRING");
@@ -529,7 +546,7 @@ public class SecurityMemberAccessTest {
// protected final static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PROTECTED_STRING");
@@ -541,7 +558,7 @@ public class SecurityMemberAccessTest {
// private static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("PRIVATE_STRING");
@@ -553,7 +570,7 @@ public class SecurityMemberAccessTest {
// private final static test
// given
assignNewSma(false);
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
method = StaticTester.getFieldByName("FINAL_PRIVATE_STRING");
@@ -566,7 +583,7 @@ public class SecurityMemberAccessTest {
@Test
public void testBlockedStaticFieldWhenClassIsExcluded() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Arrays.asList(Class.class, StaticTester.class)));
sma.setExcludedClasses(new HashSet<>(Arrays.asList(Class.class, StaticTester.class)));
// when
Member method = StaticTester.class.getField("MAX_VALUE");
@@ -579,7 +596,7 @@ public class SecurityMemberAccessTest {
@Test
public void testBlockStaticMethodAccess() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = StaticTester.class.getMethod("sayHello");
@@ -592,7 +609,7 @@ public class SecurityMemberAccessTest {
@Test
public void testBlockAccessIfClassIsExcluded() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = Class.class.getMethod("getClassLoader");
@@ -605,7 +622,7 @@ public class SecurityMemberAccessTest {
@Test
public void testBlockAccessIfClassIsExcluded_2() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
// when
Member method = ClassLoader.class.getMethod("loadClass", String.class);
@@ -619,7 +636,7 @@ public class SecurityMemberAccessTest {
@Test
public void testAllowAccessIfClassIsNotExcluded() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
// when
Member method = Class.class.getMethod("getClassLoader");
@@ -632,7 +649,7 @@ public class SecurityMemberAccessTest {
@Test
public void testIllegalArgumentExceptionExpectedForTargetMemberMismatch() throws Exception {
// given
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
// when
Member method = ClassLoader.class.getMethod("loadClass", String.class);
@@ -651,7 +668,7 @@ public class SecurityMemberAccessTest {
@Test
public void testAccessPrimitiveInt() throws Exception {
// given
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax"));
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax"));
String propertyName = "intField";
Member member = FooBar.class.getMethod(formGetterName(propertyName));
@@ -666,7 +683,7 @@ public class SecurityMemberAccessTest {
@Test
public void testAccessPrimitiveDoubleWithNames() throws Exception {
// given
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("ognl.,javax."));
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("ognl.,javax."));
Set<Class<?>> excluded = new HashSet<>();
@@ -675,7 +692,7 @@ public class SecurityMemberAccessTest {
excluded.add(System.class);
excluded.add(Class.class);
excluded.add(ClassLoader.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
String propertyName = "doubleValue";
double myDouble = 1;
@@ -721,7 +738,7 @@ public class SecurityMemberAccessTest {
// given
Set<Pattern> patterns = new HashSet<>();
patterns.add(Pattern.compile("^java\\.lang\\..*"));
sma.useExcludedPackageNamePatterns(patterns);
sma.setExcludedPackageNamePatterns(patterns);
String propertyName = "doubleValue";
double myDouble = 1;
@@ -739,7 +756,7 @@ public class SecurityMemberAccessTest {
// given
Set<Class<?>> excluded = new HashSet<>();
excluded.add(ognl.MemberAccess.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
String propertyName = "excludedClasses";
String setter = "setExcludedClasses";
@@ -757,7 +774,7 @@ public class SecurityMemberAccessTest {
// given
Set<Class<?>> excluded = new HashSet<>();
excluded.add(SecurityMemberAccess.class);
sma.useExcludedClasses(excluded);
sma.setExcludedClasses(excluded);
String propertyName = "excludedClasses";
String setter = "setExcludedClasses";
@@ -773,7 +790,7 @@ public class SecurityMemberAccessTest {
@Test
public void testPackageNameExclusionAsCommaDelimited() {
// given
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang"));
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang."));
// when
boolean actual = sma.isPackageExcluded(String.class, String.class);
@@ -1,93 +0,0 @@
/*
* 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.dispatcher;
import org.junit.Test;
import org.springframework.mock.web.MockServletContext;
import javax.servlet.ServletContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class ApplicationMapTest {
@Test
public void shouldRetrieveAttribute() {
// given
ServletContext context = new MockServletContext();
context.setAttribute("attr", "value");
// when
ApplicationMap am = new ApplicationMap(context);
Object value = am.get("attr");
// then
assertEquals("value", value);
}
@Test
public void shouldReturnNullIfKeyIsNull() {
// given
ServletContext context = new MockServletContext();
// when
ApplicationMap am = new ApplicationMap(context);
Object value = am.get(null);
// then
assertNull(value);
}
@Test
public void shouldRemoveAttributeFromServletContext() {
// given
ServletContext context = new MockServletContext();
context.setAttribute("attr", "value");
// when
ApplicationMap am = new ApplicationMap(context);
Object value = am.remove("attr");
// then
assertEquals("value", value);
assertNull(context.getAttribute("attr"));
}
@Test
public void shouldClearAttributes() {
// given
ServletContext context = new MockServletContext();
context.setAttribute("attr", "value");
// when
ApplicationMap am = new ApplicationMap(context);
Object value = am.get("attr");
// then
assertEquals("value", value);
// when
am.clear();
// then
assertNull(context.getAttribute("attr"));
}
}
@@ -1,93 +0,0 @@
/*
* 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.dispatcher;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class RequestMapTest {
@Test
public void shouldRetrieveRequestAttribute() {
// given
HttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("attr", "value");
// when
RequestMap rm = new RequestMap(request);
Object value = rm.get("attr");
// then
assertEquals("value", value);
}
@Test
public void shouldReturnNullIfKeyIsNull() {
// given
HttpServletRequest request = new MockHttpServletRequest();
// when
RequestMap rm = new RequestMap(request);
Object value = rm.get(null);
// then
assertNull(value);
}
@Test
public void shouldRemoveAttributeFromRequest() {
// given
HttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("attr", "value");
// when
RequestMap rm = new RequestMap(request);
Object value = rm.remove("attr");
// then
assertEquals("value", value);
assertNull(request.getAttribute("attr"));
}
@Test
public void shouldClearAttributes() {
// given
HttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("attr", "value");
// when
RequestMap rm = new RequestMap(request);
Object value = rm.get("attr");
// then
assertEquals("value", value);
// when
rm.clear();
// then
assertNull(request.getAttribute("attr"));
}
}
@@ -112,7 +112,7 @@ public class StrutsBackgroundProcessTest extends StrutsInternalTestCase {
executor.execute(bp);
}
Thread.sleep(500);
Thread.sleep(400);
for (BackgroundProcess bp : bps) {
assertTrue("Process is still active: " + bp, bp.isDone());
@@ -45,7 +45,7 @@ public class SecurityMemberAccessInServletsTest extends StrutsInternalTestCase {
Set<Pattern> excluded = new HashSet<Pattern>();
excluded.add(Pattern.compile("^(?!javax\\.servlet\\..+)(javax\\..+)"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
String propertyName = "value";
Member member = TagSupport.class.getMethod("doStartTag");
@@ -63,7 +63,7 @@ public class SecurityMemberAccessInServletsTest extends StrutsInternalTestCase {
Set<Pattern> excluded = new HashSet<>();
excluded.add(Pattern.compile("^javax\\..+"));
sma.useExcludedPackageNamePatterns(excluded);
sma.setExcludedPackageNamePatterns(excluded);
String propertyName = "value";
Member member = TagSupport.class.getMethod("doStartTag");
@@ -29,12 +29,9 @@ import org.springframework.mock.web.MockRequestDispatcher;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test case for StrutsUtil.
*
@@ -148,63 +145,28 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
}
public void testMakeSelectList() {
String[] selectedList = new String[]{"Car", "Airplane", "Bus"}; // Array
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
public void testMakeSelectListMethod() {
String[] selectedList = new String[] { "Car", "Airplane", "Bus" };
List list = new ArrayList();
list.add("Lorry");
list.add("Car");
list.add("Helicopter");
stack.getContext().put("mySelectedList", selectedList);
stack.getContext().put("myList", list);
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
List listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
expectedItems.put("Lorry", false);
expectedItems.put("Car", true);
expectedItems.put("Helicopter", false);
makeSelectListCommonAssertions(listMade, expectedItems);
}
public void testMakeSelectListCollection() {
List<String> selectedList = Arrays.asList("Airplane", "Helicopter", "Bus"); // Collection
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
stack.getContext().put("mySelectedList", selectedList);
stack.getContext().put("myList", list);
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
expectedItems.put("Lorry", false);
expectedItems.put("Car", false);
expectedItems.put("Helicopter", true);
makeSelectListCommonAssertions(listMade, expectedItems);
}
public void testMakeSelectListSingleton() {
String selectedItem = "Lorry"; // Singleton
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
stack.getContext().put("mySelectedList", selectedItem);
stack.getContext().put("myList", list);
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
expectedItems.put("Lorry", true);
expectedItems.put("Car", false);
expectedItems.put("Helicopter", false);
makeSelectListCommonAssertions(listMade, expectedItems);
}
private void makeSelectListCommonAssertions(List<ListEntry> listMade, LinkedHashMap<String, Boolean> expectedItems) {
assertThat(listMade).extracting("key").containsExactly(expectedItems.keySet().toArray());
assertThat(listMade).extracting("value").containsExactly(expectedItems.keySet().toArray());
assertThat(listMade).extracting("isSelected").containsExactly(expectedItems.values().toArray());
}
public void testMakeSelectListNonExistent() {
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#nonexistent", null, null);
assertThat(listMade).isEmpty();
assertEquals(listMade.size(), 3);
assertEquals(((ListEntry)listMade.get(0)).getKey(), "Lorry");
assertEquals(((ListEntry)listMade.get(0)).getValue(), "Lorry");
assertFalse(((ListEntry) listMade.get(0)).getIsSelected());
assertEquals(((ListEntry)listMade.get(1)).getKey(), "Car");
assertEquals(((ListEntry)listMade.get(1)).getValue(), "Car");
assertTrue(((ListEntry) listMade.get(1)).getIsSelected());
assertEquals(((ListEntry)listMade.get(2)).getKey(), "Helicopter");
assertEquals(((ListEntry)listMade.get(2)).getValue(), "Helicopter");
assertFalse(((ListEntry) listMade.get(2)).getIsSelected());
}
public void testToInt() {
@@ -216,22 +178,12 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
assertEquals(strutsUtil.toLong(11), 11L);
}
public void testStringToLong() {
assertEquals(11L, strutsUtil.toLong("11"));
assertEquals(0L, strutsUtil.toLong(null));
assertEquals(0L, strutsUtil.toLong(""));
}
public void testToString() {
assertEquals(strutsUtil.toString(1), "1");
assertEquals(strutsUtil.toString(11L), "11");
}
public void testToStringSafe() {
assertEquals("1", strutsUtil.toStringSafe(1));
assertEquals("", strutsUtil.toStringSafe(null));
}
public void testTranslateVariables() {
stack.push(new Object() {
public String getFoo() {
@@ -281,7 +233,7 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
// === internal class to assist in testing
protected static class InternalMockHttpServletRequest extends MockHttpServletRequest {
static class InternalMockHttpServletRequest extends MockHttpServletRequest {
InternalMockRequestDispatcher dispatcher = null;
public RequestDispatcher getRequestDispatcher(String path) {
dispatcher = new InternalMockRequestDispatcher(path);
@@ -293,8 +245,8 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
}
}
protected static class InternalMockRequestDispatcher extends MockRequestDispatcher {
private final String url;
static class InternalMockRequestDispatcher extends MockRequestDispatcher {
private String url;
boolean included = false;
public InternalMockRequestDispatcher(String url) {
super(url);
+8 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-async-plugin</artifactId>
@@ -36,6 +36,13 @@
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mockobjects</groupId>
<artifactId>mockobjects-core</artifactId>
+13 -2
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -55,6 +55,17 @@
<artifactId>javax.el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<!-- this library is excluded in the parent pom as it clashes with Easymock dependencies -->
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>3.2</version>
</dependency>
<!--
The Java EE API modules listed below are all marked @Deprecated(forRemoval=true), because they are scheduled
@@ -77,7 +88,7 @@
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
+8 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-cdi-plugin</artifactId>
@@ -58,6 +58,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-config-browser-plugin</artifactId>
+8 -14
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-convention-plugin</artifactId>
@@ -49,6 +49,10 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
@@ -59,25 +63,15 @@
</dependency>
<!-- testing -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-dwr-plugin</artifactId>
+10 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-embeddedjsp-plugin</artifactId>
@@ -32,6 +32,10 @@
<name>DEPRECATED: Struts 2 Embedded JSP Plugin, since 6.0.0</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
@@ -61,6 +65,11 @@
<artifactId>request</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-gxp-plugin</artifactId>
+11 -2
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-jasperreports-plugin</artifactId>
@@ -32,10 +32,14 @@
<name>Struts 2 Jasper Reports Plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.20.5</version>
<version>6.19.1</version>
<scope>provided</scope>
<exclusions>
<!-- not necessary to compile and it force dependency convergence issues -->
@@ -58,6 +62,11 @@
<artifactId>struts2-junit-plugin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
+9 -1
View File
@@ -25,7 +25,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-javatemplates-plugin</artifactId>
@@ -33,6 +33,14 @@
<name>Struts 2 Java Templates Plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
+6 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-jfreechart-plugin</artifactId>
@@ -61,6 +61,11 @@
<artifactId>struts2-junit-plugin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
+23 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-json-plugin</artifactId>
@@ -54,6 +54,22 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
@@ -83,6 +99,12 @@
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
+4 -1
View File
@@ -1,4 +1,7 @@
# Struts 2 JUnit plugin
# Struts 2 JFreeChart plugin
The JUnit Plugin supports testing actions within a Struts invocation, meaning that a full request is simulated,
and the output of the action can be tested.
You will find more details in [documentation](https://struts.apache.org/plugins/junit/).
## Installation
Just drop this plugin JAR into `WEB-INF/lib` folder or add it as a Maven dependency.
+33 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-junit-plugin</artifactId>
@@ -49,10 +49,42 @@
<artifactId>struts2-spring-plugin</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<!-- Convention Plugin tests -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<scope>test</scope>
</dependency>
<!-- Portlet -->
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-plugin</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-mocks-plugin</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
@@ -35,6 +35,19 @@ import javax.portlet.PortletMode;
import java.util.HashMap;
import java.util.Map;
/*
* Changes: This is a copy of org.apache.struts2.StrutsPortletTestCase from the Struts 2 portlet-plugin, moved
* into the junit-plugin (same package org.apache.struts2).
* The import order above was changed to alphabetical.
*
* Note: The assumption is that anyone utilizing StrutsPortletTestCase currently from the portlet-plugin will almost
* certainly be using the junit-plugin. Under that assumption, the refactored-move of StrutsPortletTestCase
* should not cause issues for pre-existing usage of StrutsPortletTestCase.
*/
/**
* Base class used to test action in portlet environment
*/
public abstract class StrutsPortletTestCase extends StrutsTestCase {
private static final Logger LOG = LogManager.getLogger(StrutsPortletTestCase.class);
@@ -82,7 +95,7 @@ public abstract class StrutsPortletTestCase extends StrutsTestCase {
* @return Map with session parameters
*/
private Map<String, Object> createSession() {
return new HashMap<>(portletRequest.getPortletSession().getAttributeMap());
return new HashMap<String, Object>(portletRequest.getPortletSession().getAttributeMap());
}
}
@@ -21,10 +21,9 @@ package actions;
import com.opensymphony.xwork2.ActionSupport;
/**
* Example action, called by {@link org.apache.struts2.convention.ConventionJUnit4Test}.
* Result defined by message-success.ftl.
* Example action, which is called by the convention plugin test case
*/
public class MessageAction extends ActionSupport {
public class ViewAction extends ActionSupport {
private String message;
public String getMessage() {
@@ -19,9 +19,13 @@
package org.apache.struts2.junit;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.junit.Test;
import javax.portlet.PortletContext;
import javax.servlet.ServletException;
import java.io.UnsupportedEncodingException;
@@ -60,4 +64,38 @@ public class StrutsTestCaseTest extends StrutsSpringTestCase {
String name = (String) findValueAfterExecute("name");
assertEquals("FD", name);
}
@Test
public void shouldPortletContextBeAvailable() throws Exception {
// given
assertNull(ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT));
// when
String output = executeAction("/test/testAction.action");
assertEquals("Hello", output);
// then
Object portletContext = ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
assertNotNull(portletContext);
assertTrue(portletContext instanceof PortletContext);
}
@Test
public void shouldAdditionalContextParamsBeAvailable() throws Exception {
// given
String key = "my-param";
assertNull(ActionContext.getContext().get(key));
// when
String output = executeAction("/test/testAction.action");
assertEquals("Hello", output);
// then
assertNotNull(ActionContext.getContext().get(key));
}
@Override
protected void applyAdditionalParams(ActionContext context) {
context.put("my-param", new Object());
}
}
@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.convention;
package org.apache.struts2.junit.convention;
import actions.MessageAction;
import actions.ViewAction;
import org.apache.struts2.junit.StrutsJUnit4TestCase;
import org.junit.Test;
@@ -28,17 +28,17 @@ import static org.junit.Assert.assertTrue;
/**
* Uses the convention plugin to execute actions
*/
public class ConventionJUnit4Test extends StrutsJUnit4TestCase<MessageAction> {
public class StrutsJUnit4ConventionTestCaseTest extends StrutsJUnit4TestCase<ViewAction> {
@Test
public void testConventionUrl() throws Exception {
// Output is filled out only for FreeMarker and Velocity templates
// If you wanna use JSP check response.getForwardedUrl()
String output = executeAction("/message.action");
String output = executeAction("/view.action");
assertTrue(output.contains("This is the view Hello World"));
MessageAction action = this.getAction();
ViewAction action = this.getAction();
assertEquals("Hello World", action.getMessage());
}
@@ -48,5 +48,6 @@ public class ConventionJUnit4Test extends StrutsJUnit4TestCase<MessageAction> {
// struts-convention-configuration.xml overrides some settings from plugin to allow work in limited environment
return "struts-plugin.xml,struts-convention-configuration.xml";
}
}
@@ -25,7 +25,14 @@
"https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<!-- result is defined in test/resources -->
<constant name="struts.convention.result.path" value="/"/>
<package name="convention-default" extends="struts-default"/>
<!-- This is needed as there is struts2-spring-plugin on classpath -->
<constant name="struts.objectFactory" value="struts"/>
<package name="convention-default" extends="struts-default">
</package>
</struts>
+15 -2
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-osgi-plugin</artifactId>
@@ -38,7 +38,7 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>8.0.0</version>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -84,6 +84,11 @@
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
@@ -100,6 +105,14 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+6 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-oval-plugin</artifactId>
@@ -49,6 +49,11 @@
<artifactId>xstream</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-pell-multipart-plugin</artifactId>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-plexus-plugin</artifactId>
+1 -24
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-parent</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-plugins</artifactId>
@@ -50,7 +50,6 @@
<module>pell-multipart</module>
<module>plexus</module>
<module>portlet</module>
<module>portlet-junit</module>
<module>portlet-mocks</module>
<module>portlet-tiles</module>
<module>rest</module>
@@ -67,7 +66,6 @@
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
@@ -76,28 +74,7 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
-2
View File
@@ -1,2 +0,0 @@
# Struts 2 Portlet JUnit plugin
The Portlet JUnit Plugin supports testing applications that use the Portlet Plugin.
-58
View File
@@ -1,58 +0,0 @@
<?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.
*/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
</parent>
<artifactId>struts2-portlet-junit-plugin</artifactId>
<packaging>jar</packaging>
<name>DEPRECATED: Struts 2 Portlet JUnit Plugin - since 6.3.0</name>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-plugin</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-mocks-plugin</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
-56
View File
@@ -1,56 +0,0 @@
<?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.
*/
-->
<project name="Apache Struts">
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>${fluido-skin.version}</version>
</skin>
<bannerLeft>
<name>Apache Software Foundation</name>
<src>http://www.apache.org/images/asf-logo.gif</src>
<href>http://www.apache.org/</href>
</bannerLeft>
<bannerRight>
<name>Apache Struts</name>
<src>http://struts.apache.org/img/struts-logo.svg</src>
<href>http://struts.apache.org/</href>
</bannerRight>
<publishDate position="left"/>
<version position="right"/>
<body>
<links>
<item name="Apache" href="http://www.apache.org/"/>
<item name="Struts" href="http://struts.apache.org/"/>
</links>
<menu ref="parent"/>
<menu ref="reports"/>
<footer>
<![CDATA[<div class="row span12">
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project
logos are trademarks of The Apache Software Foundation.
</div>]]>
</footer>
</body>
</project>
@@ -1,64 +0,0 @@
/*
* 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.junit;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import org.apache.struts2.StrutsStatics;
import javax.portlet.PortletContext;
public class StrutsPortletTestCaseTest extends StrutsPortletTestCase {
String KEY = "my-param";
public void testShouldPortletContextBeAvailable() throws Exception {
// given
assertNull(ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT));
// when
ActionProxy proxy = getActionProxy("/test/testAction.action");
String result = proxy.execute();
// then
assertEquals(Action.SUCCESS, result);
Object portletContext = ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
assertNotNull(portletContext);
assertTrue(portletContext instanceof PortletContext);
}
public void testShouldAdditionalContextParamsBeAvailable() throws Exception {
// given
assertNull(ActionContext.getContext().get(KEY));
// when
ActionProxy proxy = getActionProxy("/test/testAction.action");
String result = proxy.execute();
// then
assertEquals(Action.SUCCESS, result);
assertNotNull(ActionContext.getContext().get(KEY));
}
@Override
protected void applyAdditionalParams(ActionContext context) {
context.put(KEY, new Object());
}
}
@@ -1,34 +0,0 @@
<?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.
*/
-->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"https://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="test" namespace="/test" extends="struts-default">
<action name="testAction" class="com.opensymphony.xwork2.ActionSupport">
<result name="success" type="httpheader">
<param name="status">200</param>
</result>
</action>
</package>
</struts>
+1 -1
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-portlet-mocks-plugin</artifactId>
+13 -4
View File
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
<version>6.3.0.1</version>
<version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>struts2-portlet-tiles-plugin</artifactId>
@@ -40,15 +40,24 @@
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-portlet</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
@@ -22,9 +22,9 @@ import com.opensymphony.xwork2.ActionInvocation;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.result.ServletDispatcherResult;
import org.apache.tiles.api.TilesContainer;
import org.apache.tiles.api.TilesException;
import org.apache.tiles.api.access.TilesAccess;
import org.apache.tiles.TilesContainer;
import org.apache.tiles.TilesException;
import org.apache.tiles.access.TilesAccess;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
import org.apache.tiles.request.portlet.RenderPortletRequest;
@@ -1,344 +0,0 @@
/*
* $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.tiles.request.portlet;
import org.apache.tiles.request.AbstractClientRequest;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.attribute.Addable;
import org.apache.tiles.request.collection.HeaderValuesMap;
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
import org.apache.tiles.request.collection.ScopeMap;
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
import org.apache.tiles.request.portlet.extractor.RequestScopeExtractor;
import org.apache.tiles.request.portlet.extractor.SessionScopeExtractor;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Portlet-based TilesApplicationContext implementation.
*/
public class PortletRequest extends AbstractClientRequest {
/**
* The native available scopes.
*/
private static final List<String> SCOPES = Collections.unmodifiableList(Arrays.asList(REQUEST_SCOPE, "portletSession", "session", APPLICATION_SCOPE));
/**
* <p>The lazily instantiated <code>Map</code> of header name-value
* combinations (immutable).</p>
*/
private Map<String, String> header = null;
/**
* <p>The lazily instantiated <code>Map</code> of header name-value
* combinations (write-only).</p>
*/
private Addable<String> responseHeaders = null;
/**
* <p>The lazily instantiated <code>Map</code> of header name-values
* combinations (immutable).</p>
*/
private Map<String, String[]> headerValues = null;
/**
* The <code>PortletContext</code> for this application.
*/
protected PortletContext context;
/**
* <p>The <code>PortletRequest</code> for this request.</p>
*/
protected javax.portlet.PortletRequest request;
/**
* The delegate to get information about parameters.
*/
protected RequestDelegate requestDelegate;
/**
* <p>The lazily instantiated <code>Map</code> of request scope
* attributes.</p>
*/
private Map<String, Object> requestScope = null;
/**
* <p>The <code>PortletResponse</code> for this request.</p>
*/
protected PortletResponse response;
/**
* The delegate to get information from a response (output stream, writer, etc.).
*/
protected ResponseDelegate responseDelegate;
/**
* <p>The lazily instantiated <code>Map</code> of session scope
* attributes.</p>
*/
private Map<String, Object> sessionScope = null;
/**
* <p>The lazily instantiated <code>Map</code> of portlet session scope
* attributes.</p>
*/
private Map<String, Object> portletSessionScope = null;
/**
* Creates a new instance of PortletTilesRequestContext.
*
* @param applicationContext The Tiles application context.
* @param context The portlet context to use.
* @param request The request object to use.
* @param response The response object to use.
* @param requestDelegate The request delegate.
* @param responseDelegate The response delegate.
*/
public PortletRequest(ApplicationContext applicationContext,
PortletContext context, javax.portlet.PortletRequest request,
PortletResponse response, RequestDelegate requestDelegate, ResponseDelegate responseDelegate) {
super(applicationContext);
// Save the specified Portlet API object references
this.context = context;
this.request = request;
this.response = response;
this.requestDelegate = requestDelegate;
this.responseDelegate = responseDelegate;
}
/**
* <p>Return the {@link PortletRequest} for this context.</p>
*
* @return The used portlet request.
*/
public javax.portlet.PortletRequest getRequest() {
return (this.request);
}
/**
* Returns the portlet context.
*
* @return The portlet context.
*/
public PortletContext getPortletContext() {
return context;
}
/**
* {@inheritDoc}
*/
public Map<String, String> getHeader() {
if ((header == null) && (request != null)) {
header = new ReadOnlyEnumerationMap<>(new HeaderExtractor(request, null));
}
return (header);
}
/**
* {@inheritDoc}
*/
public Addable<String> getResponseHeaders() {
if ((responseHeaders == null) && (request != null)) {
responseHeaders = new HeaderExtractor(null, response);
}
return (responseHeaders);
}
/**
* {@inheritDoc}
*/
public Map<String, String[]> getHeaderValues() {
if ((headerValues == null) && (request != null)) {
headerValues = new HeaderValuesMap(new HeaderExtractor(request, response));
}
return (headerValues);
}
/**
* {@inheritDoc}
*/
public Map<String, Object> getRequestScope() {
if ((requestScope == null) && (request != null)) {
requestScope = new ScopeMap(new RequestScopeExtractor(request));
}
return (requestScope);
}
/**
* {@inheritDoc}
*/
public Map<String, Object> getSessionScope() {
if ((sessionScope == null) && (request != null)) {
sessionScope = new ScopeMap(new SessionScopeExtractor(request,
PortletSession.APPLICATION_SCOPE));
}
return (sessionScope);
}
/**
* {@inheritDoc}
*/
public Map<String, Object> getPortletSessionScope() {
if ((portletSessionScope == null) && (request != null)) {
portletSessionScope = new ScopeMap(new SessionScopeExtractor(
request, PortletSession.APPLICATION_SCOPE));
}
return (portletSessionScope);
}
@Override
public List<String> getAvailableScopes() {
return SCOPES;
}
/**
* {@inheritDoc}
*/
public Locale getRequestLocale() {
return request.getLocale();
}
@Override
public Map<String, String> getParam() {
return requestDelegate.getParam();
}
@Override
public Map<String, String[]> getParamValues() {
return requestDelegate.getParamValues();
}
/**
* {@inheritDoc}
*/
public boolean isUserInRole(String role) {
return request.isUserInRole(role);
}
@Override
public OutputStream getOutputStream() throws IOException {
return responseDelegate.getOutputStream();
}
@Override
public PrintWriter getPrintWriter() throws IOException {
return responseDelegate.getPrintWriter();
}
@Override
public Writer getWriter() throws IOException {
return responseDelegate.getWriter();
}
@Override
public boolean isResponseCommitted() {
return responseDelegate.isResponseCommitted();
}
@Override
public void setContentType(String contentType) {
responseDelegate.setContentType(contentType);
}
/**
* {@inheritDoc}
*/
public void doForward(String path) throws IOException {
if (responseDelegate.isResponseCommitted()) {
doInclude(path);
return;
}
try {
PortletRequestDispatcher rd = getPortletContext()
.getRequestDispatcher(path);
if (rd == null) {
throw new IOException(
"No portlet request dispatcher returned for path '"
+ path + "'");
}
rd.forward(request, response);
} catch (PortletException e) {
throw new IOException("PortletException while including path '"
+ path + "'.", e);
}
}
/**
* {@inheritDoc}
*/
public void doInclude(String path) throws IOException {
try {
PortletRequestDispatcher rd = getPortletContext()
.getRequestDispatcher(path);
if (rd == null) {
throw new IOException(
"No portlet request dispatcher returned for path '"
+ path + "'");
}
rd.include(request, response);
} catch (PortletException e) {
throw new IOException("PortletException while including path '"
+ path + "'.", e);
}
}
@Override
public Map<String, Object> getContext(String scope) {
if (REQUEST_SCOPE.equals(scope)) {
return getRequestScope();
} else if ("session".equals(scope)) {
return getSessionScope();
} else if ("portletSession".equals(scope)) {
return getPortletSessionScope();
} else if (APPLICATION_SCOPE.equals(scope)) {
return getApplicationScope();
}
throw new IllegalArgumentException(scope + " does not exist. Call getAvailableScopes() first to check.");
}
}
@@ -1,47 +0,0 @@
/*
* $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.tiles.request.portlet;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
import javax.portlet.PortletContext;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* Portlet request for a {@link RenderRequest}.
*/
public class RenderPortletRequest extends PortletRequest {
/**
* Constructor.
*
* @param applicationContext The application context.
* @param context The portlet context.
* @param request The portlet request.
* @param response The portlet response.
*/
public RenderPortletRequest(ApplicationContext applicationContext, PortletContext context, RenderRequest request, RenderResponse response) {
super(applicationContext, context, request, response, new PortletRequestDelegate(request), new MimeResponseDelegate(response));
}
}
@@ -1,72 +0,0 @@
/*
* $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.tiles.request.portlet.delegate;
import javax.portlet.MimeResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
/**
* Response delegate in case of {@link MimeResponse}.
*/
public class MimeResponseDelegate implements ResponseDelegate {
/**
* The response.
*/
private final MimeResponse response;
/**
* Constructor.
*
* @param response The response.
*/
public MimeResponseDelegate(MimeResponse response) {
this.response = response;
}
/** {@inheritDoc} */
public OutputStream getOutputStream() throws IOException {
return response.getPortletOutputStream();
}
/** {@inheritDoc} */
public PrintWriter getPrintWriter() throws IOException {
return response.getWriter();
}
/** {@inheritDoc} */
public Writer getWriter() throws IOException {
return response.getWriter();
}
/** {@inheritDoc} */
public boolean isResponseCommitted() {
return response.isCommitted();
}
/** {@inheritDoc} */
public void setContentType(String contentType) {
response.setContentType(contentType);
}
}
@@ -1,79 +0,0 @@
/*
* $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.tiles.request.portlet.delegate;
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
import javax.portlet.PortletRequest;
import java.util.Map;
/**
* Request delegate in case of simple Portlet request.
*/
public class PortletRequestDelegate implements RequestDelegate {
/**
* The request.
*/
private final PortletRequest request;
/**
* <p>The lazily instantiated <code>Map</code> of request
* parameter name-value.</p>
*/
private Map<String, String> param = null;
/**
* <p>The lazily instantiated <code>Map</code> of request
* parameter name-values.</p>
*/
private Map<String, String[]> paramValues = null;
/**
* Constructor.
*
* @param request The request.
*/
public PortletRequestDelegate(PortletRequest request) {
this.request = request;
}
/**
* {@inheritDoc}
*/
public Map<String, String> getParam() {
if ((param == null) && (request != null)) {
param = new ReadOnlyEnumerationMap<>(new ParameterExtractor(request));
}
return (param);
}
/**
* {@inheritDoc}
*/
public Map<String, String[]> getParamValues() {
if ((paramValues == null) && (request != null)) {
paramValues = request.getParameterMap();
}
return (paramValues);
}
}
@@ -1,43 +0,0 @@
/*
* $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.tiles.request.portlet.delegate;
import java.util.Map;
/**
* Exposes the parameters of a portlet request, if available.
*/
public interface RequestDelegate {
/**
* The parameters, as single values.
*
* @return The parameters.
*/
Map<String, String> getParam();
/**
* The parameters, with values as array of strings.
*
* @return The parameters.
*/
Map<String, String[]> getParamValues();
}
@@ -1,70 +0,0 @@
/*
* $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.tiles.request.portlet.delegate;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
/**
* Exposes features of a response, if they are available.
*/
public interface ResponseDelegate {
/**
* Returns the output stream.
*
* @return The output stream.
* @throws IOException If the underlying response causes a problem.
*/
OutputStream getOutputStream() throws IOException;
/**
* Returns the print writer.
*
* @return The print writer.
* @throws IOException If the underlying response causes a problem.
*/
PrintWriter getPrintWriter() throws IOException;
/**
* Returns the writer.
*
* @return The writer.
* @throws IOException If the underlying response causes a problem.
*/
Writer getWriter() throws IOException;
/**
* Sets the content type of the response.
*
* @param contentType The content type.
*/
void setContentType(String contentType);
/**
* Checks if the response is committed.
*
* @return <code>true</code> if the response is committed.
*/
boolean isResponseCommitted();
}
@@ -1,24 +0,0 @@
/*
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
*
* 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.
*/
/**
* Delegations to map all the different types of request and responses.
*/
package org.apache.tiles.request.portlet.delegate;
@@ -1,66 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.AttributeExtractor;
import javax.portlet.PortletContext;
import java.util.Enumeration;
/**
* Extracts attributes from portlet application scope.
*/
public class ApplicationScopeExtractor implements AttributeExtractor {
/**
* The portlet context.
*/
private final PortletContext context;
/**
* Constructor.
*
* @param context The portlet context.
*/
public ApplicationScopeExtractor(PortletContext context) {
this.context = context;
}
@Override
public void setValue(String name, Object value) {
context.setAttribute(name, value);
}
@Override
public void removeValue(String name) {
context.removeAttribute(name);
}
@Override
public Enumeration<String> getKeys() {
return context.getAttributeNames();
}
@Override
public Object getValue(String key) {
return context.getAttribute(key);
}
}
@@ -1,74 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.EnumeratedValuesExtractor;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import java.util.Enumeration;
/**
* Extracts and puts headers in portlet requests and responses.
*/
public class HeaderExtractor implements EnumeratedValuesExtractor {
/**
* The request.
*/
private final PortletRequest request;
/**
* The response.
*/
private final PortletResponse response;
/**
* Constructor.
*
* @param request The request.
* @param response The response.
*/
public HeaderExtractor(PortletRequest request, PortletResponse response) {
this.request = request;
this.response = response;
}
@Override
public Enumeration<String> getKeys() {
return request.getPropertyNames();
}
@Override
public String getValue(String key) {
return request.getProperty(key);
}
@Override
public Enumeration<String> getValues(String key) {
return request.getProperties(key);
}
@Override
public void setValue(String key, String value) {
response.setProperty(key, value);
}
}
@@ -1,57 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.HasKeys;
import javax.portlet.PortletContext;
import java.util.Enumeration;
/**
* Extracts init parameters from a portlet context.
*/
public class InitParameterExtractor implements HasKeys<String> {
/**
* The portlet context.
*/
private final PortletContext context;
/**
* Constructor.
*
* @param context The portlet context.
*/
public InitParameterExtractor(PortletContext context) {
this.context = context;
}
@Override
public Enumeration<String> getKeys() {
return context.getInitParameterNames();
}
@Override
public String getValue(String key) {
return context.getInitParameter(key);
}
}
@@ -1,56 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.HasKeys;
import javax.portlet.PortletRequest;
import java.util.Enumeration;
/**
* Extracts parameters from a portlet request.
*/
public class ParameterExtractor implements HasKeys<String> {
/**
* The portlet request.
*/
private final PortletRequest request;
/**
* Constructor.
*
* @param request The portlet request.
*/
public ParameterExtractor(PortletRequest request) {
this.request = request;
}
@Override
public Enumeration<String> getKeys() {
return request.getParameterNames();
}
@Override
public String getValue(String key) {
return request.getParameter(key);
}
}
@@ -1,66 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.AttributeExtractor;
import javax.portlet.PortletRequest;
import java.util.Enumeration;
/**
* Extracts attributes from request scope of a portlet request.
*/
public class RequestScopeExtractor implements AttributeExtractor {
/**
* The portlet request.
*/
private final PortletRequest request;
/**
* Constructor.
*
* @param request The portlet request.
*/
public RequestScopeExtractor(PortletRequest request) {
this.request = request;
}
@Override
public void setValue(String name, Object value) {
request.setAttribute(name, value);
}
@Override
public void removeValue(String name) {
request.removeAttribute(name);
}
@Override
public Enumeration<String> getKeys() {
return request.getAttributeNames();
}
@Override
public Object getValue(String key) {
return request.getAttribute(key);
}
}
@@ -1,88 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.AttributeExtractor;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import java.util.Enumeration;
/**
* Extracts attributes from the session scope of a portlet request.
*/
public class SessionScopeExtractor implements AttributeExtractor {
/**
* The portlet request.
*/
private final PortletRequest request;
/**
* The subscope (application or portlet).
*/
private final int scope;
/**
* Constructor.
*
* @param request The request.
* @param scope The subscope (application or portlet).
*/
public SessionScopeExtractor(PortletRequest request, int scope) {
this.request = request;
if (scope != PortletSession.APPLICATION_SCOPE && scope != PortletSession.PORTLET_SCOPE) {
throw new IllegalArgumentException("The scope must be either APPLICATION_SCOPE or PORTLET_SCOPE");
}
this.scope = scope;
}
@Override
public void setValue(String name, Object value) {
request.getPortletSession().setAttribute(name, value, scope);
}
@Override
public void removeValue(String name) {
PortletSession session = request.getPortletSession(false);
if (session != null) {
session.removeAttribute(name, scope);
}
}
@Override
public Enumeration<String> getKeys() {
PortletSession session = request.getPortletSession(false);
if (session != null) {
return session.getAttributeNames(scope);
}
return null;
}
@Override
public Object getValue(String key) {
PortletSession session = request.getPortletSession(false);
if (session != null) {
return session.getAttribute(key, scope);
}
return null;
}
}
@@ -1,53 +0,0 @@
/*
* $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.tiles.request.portlet.extractor;
import org.apache.tiles.request.attribute.HasAddableKeys;
import javax.portlet.PortletRequest;
import javax.portlet.StateAwareResponse;
/**
* Extracts parameters from a request and allows putting render parameters in a state aware response.
*/
public class StateAwareParameterExtractor extends ParameterExtractor implements HasAddableKeys<String> {
/**
* The portlet response.
*/
private final StateAwareResponse response;
/**
* Constructor.
*
* @param request The portlet request.
* @param response The portlet response.
*/
public StateAwareParameterExtractor(PortletRequest request, StateAwareResponse response) {
super(request);
this.response = response;
}
@Override
public void setValue(String key, String value) {
response.setRenderParameter(key, value);
}
}
@@ -1,24 +0,0 @@
/*
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
*
* 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.
*/
/**
* Extractors to get scopes from Portlet requests.
*/
package org.apache.tiles.request.portlet.extractor;
@@ -1,24 +0,0 @@
/*
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
*
* 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.
*/
/**
* Support of Tiles requests to portlets.
*/
package org.apache.tiles.request.portlet;
@@ -1,424 +0,0 @@
/*
* 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.tiles.request.portlet;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.collection.HeaderValuesMap;
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
import org.apache.tiles.request.collection.ScopeMap;
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Map;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests {@link PortletRequest}.
*/
public class PortletRequestTest {
/**
* The application context.
*/
private ApplicationContext applicationContext;
/**
* The portlet context.
*/
private PortletContext portletContext;
/**
* The request.
*/
private javax.portlet.PortletRequest request;
/**
* The response.
*/
private PortletResponse response;
/**
* The request to test.
*/
private PortletRequest req;
/**
* The request delegate.
*/
private RequestDelegate requestDelegate;
/**
* The response delegate.
*/
private ResponseDelegate responseDelegate;
/**
* Sets up the test.
*/
@Before
public void setUp() {
applicationContext = createMock(ApplicationContext.class);
portletContext = createMock(PortletContext.class);
request = createMock(javax.portlet.PortletRequest.class);
response = createMock(PortletResponse.class);
requestDelegate = createMock(RequestDelegate.class);
responseDelegate = createMock(ResponseDelegate.class);
req = new PortletRequest(applicationContext, portletContext, request,
response, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#doForward(String)}.
*
* @throws IOException If something goes wrong.
* @throws PortletException If something goes wrong.
*/
@Test
public void testDoForward() throws PortletException, IOException {
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
expect(responseDelegate.isResponseCommitted()).andReturn(false);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
rd.forward(request, response);
replay(applicationContext, portletContext, request, response, rd);
req.doForward("/my/path");
verify(applicationContext, portletContext, request, response, rd);
}
/**
* Test method for {@link PortletRequest#doForward(String)}.
*
* @throws IOException If something goes wrong.
*/
@Test(expected = IOException.class)
public void testDoForwardNoDispatcher() throws IOException {
expect(responseDelegate.isResponseCommitted()).andReturn(false);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
try {
req.doForward("/my/path");
} finally {
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
}
/**
* Test method for {@link PortletRequest#doForward(String)}.
*
* @throws IOException If something goes wrong.
* @throws PortletException If something goes wrong.
*/
@Test(expected = IOException.class)
public void testDoForwardPortletException() throws PortletException, IOException {
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
expect(responseDelegate.isResponseCommitted()).andReturn(false);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
rd.forward(request, response);
expectLastCall().andThrow(new PortletException());
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
try {
req.doForward("/my/path");
} finally {
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
}
}
/**
* Test method for {@link PortletRequest#doForward(String)}.
*
* @throws IOException If something goes wrong.
* @throws PortletException If something goes wrong.
*/
@Test
public void testDoForwardInclude() throws PortletException, IOException {
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
expect(responseDelegate.isResponseCommitted()).andReturn(true);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
rd.include(request, response);
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
req.doForward("/my/path");
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#doInclude(String)}.
*
* @throws IOException If something goes wrong.
* @throws PortletException If something goes wrong.
*/
@Test
public void testDoInclude() throws IOException, PortletException {
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
rd.include(request, response);
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
req.doInclude("/my/path");
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#doInclude(String)}.
*
* @throws IOException If something goes wrong.
*/
@Test(expected = IOException.class)
public void testDoIncludeNoDispatcher() throws IOException {
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
try {
req.doInclude("/my/path");
} finally {
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
}
/**
* Test method for {@link PortletRequest#doInclude(String)}.
*
* @throws IOException If something goes wrong.
* @throws PortletException If something goes wrong.
*/
@Test(expected = IOException.class)
public void testDoIncludePortletException() throws IOException, PortletException {
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
rd.include(request, response);
expectLastCall().andThrow(new PortletException());
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
try {
req.doInclude("/my/path");
} finally {
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
}
}
/**
* Test method for {@link PortletRequest#getHeader()}.
*/
@Test
public void testGetHeader() {
assertTrue(req.getHeader() instanceof ReadOnlyEnumerationMap);
}
/**
* Test method for {@link PortletRequest#getResponseHeaders()}.
*/
@Test
public void testGetResponseHeaders() {
assertTrue(req.getResponseHeaders() instanceof HeaderExtractor);
}
/**
* Test method for {@link PortletRequest#getHeaderValues()}.
*/
@Test
public void testGetHeaderValues() {
assertTrue(req.getHeaderValues() instanceof HeaderValuesMap);
}
/**
* Test method for {@link PortletRequest#getParam()}.
*/
@Test
public void testGetParam() {
Map<String, String> map = createMock(Map.class);
expect(requestDelegate.getParam()).andReturn(map);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
assertEquals(map, req.getParam());
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getParamValues()}.
*/
@Test
public void testGetParamValues() {
Map<String, String[]> paramMap = createMock(Map.class);
expect(requestDelegate.getParamValues()).andReturn(paramMap);
replay(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
assertEquals(paramMap, req.getParamValues());
verify(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getRequestScope()}.
*/
@Test
public void testGetRequestScope() {
assertTrue(req.getRequestScope() instanceof ScopeMap);
}
/**
* Test method for {@link PortletRequest#getSessionScope()}.
*/
@Test
public void testGetSessionScope() {
assertTrue(req.getSessionScope() instanceof ScopeMap);
}
/**
* Test method for {@link PortletRequest#getPortletSessionScope()}.
*/
@Test
public void testGetPortletSessionScope() {
assertTrue(req.getPortletSessionScope() instanceof ScopeMap);
}
/**
* Test method for {@link PortletRequest#getOutputStream()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetOutputStream() throws IOException {
ServletOutputStream os = createMock(ServletOutputStream.class);
expect(responseDelegate.getOutputStream()).andReturn(os);
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
assertEquals(req.getOutputStream(), os);
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getWriter()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetWriter() throws IOException {
PrintWriter os = createMock(PrintWriter.class);
expect(responseDelegate.getWriter()).andReturn(os);
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
assertEquals(req.getWriter(), os);
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getPrintWriter()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetPrintWriter() throws IOException {
PrintWriter os = createMock(PrintWriter.class);
expect(responseDelegate.getPrintWriter()).andReturn(os);
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
assertEquals(req.getPrintWriter(), os);
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#isResponseCommitted()}.
*/
@Test
public void testIsResponseCommitted() {
expect(responseDelegate.isResponseCommitted()).andReturn(true);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
assertTrue(req.isResponseCommitted());
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#setContentType(String)}.
*/
@Test
public void testSetContentType() {
responseDelegate.setContentType("text/html");
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
req.setContentType("text/html");
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getRequestLocale()}.
*/
@Test
public void testGetRequestLocale() {
Locale locale = Locale.ITALY;
expect(request.getLocale()).andReturn(locale);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
assertEquals(locale, req.getRequestLocale());
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#getRequest()}.
*/
@Test
public void testGetRequest() {
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
assertEquals(request, req.getRequest());
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
/**
* Test method for {@link PortletRequest#isUserInRole(String)}.
*/
@Test
public void testIsUserInRole() {
expect(request.isUserInRole("myrole")).andReturn(true);
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
assertTrue(req.isUserInRole("myrole"));
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
}
}
@@ -1,69 +0,0 @@
/*
* 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.tiles.request.portlet;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
import org.junit.Test;
import javax.portlet.PortletContext;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.lang.reflect.Field;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertTrue;
/**
* Tests {@link RenderPortletRequest}.
*/
public class RenderPortletRequestTest {
/**
* Test method for
* {@link RenderPortletRequest#RenderPortletRequest(ApplicationContext, PortletContext,
* RenderRequest, RenderResponse)}.
*
* @throws NoSuchFieldException If something goes wrong.
* @throws SecurityException If something goes wrong.
* @throws IllegalAccessException If something goes wrong.
* @throws IllegalArgumentException If something goes wrong.
*/
@Test
public void testRenderPortletRequest() throws NoSuchFieldException, IllegalAccessException {
ApplicationContext applicationContext = createMock(ApplicationContext.class);
PortletContext portletContext = createMock(PortletContext.class);
RenderRequest request = createMock(RenderRequest.class);
RenderResponse response = createMock(RenderResponse.class);
replay(applicationContext, portletContext, request, response);
RenderPortletRequest req = new RenderPortletRequest(applicationContext,
portletContext, request, response);
Class<? extends RenderPortletRequest> clazz = req.getClass();
Field field = clazz.getSuperclass().getDeclaredField("requestDelegate");
assertTrue(field.get(req) instanceof PortletRequestDelegate);
field = clazz.getSuperclass().getDeclaredField("responseDelegate");
assertTrue(field.get(req) instanceof MimeResponseDelegate);
verify(applicationContext, portletContext, request, response);
}
}
@@ -1,132 +0,0 @@
/*
* 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.tiles.request.portlet.delegate;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.MimeResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests {@link MimeResponseDelegate}.
*/
public class MimeResponseDelegateTest {
/**
* The response.
*/
private MimeResponse response;
/**
* The delegate to test.
*/
private MimeResponseDelegate delegate;
/**
* Sets up the test.
*/
@Before
public void setUp() {
response = createMock(MimeResponse.class);
delegate = new MimeResponseDelegate(response);
}
/**
* Test method for {@link MimeResponseDelegate#getOutputStream()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetOutputStream() throws IOException {
OutputStream os = createMock(OutputStream.class);
expect(response.getPortletOutputStream()).andReturn(os);
replay(response, os);
assertEquals(os, delegate.getOutputStream());
verify(response, os);
}
/**
* Test method for {@link MimeResponseDelegate#getPrintWriter()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetPrintWriter() throws IOException {
PrintWriter os = createMock(PrintWriter.class);
expect(response.getWriter()).andReturn(os);
replay(response, os);
assertEquals(os, delegate.getPrintWriter());
verify(response, os);
}
/**
* Test method for {@link MimeResponseDelegate#getWriter()}.
*
* @throws IOException If something goes wrong.
*/
@Test
public void testGetWriter() throws IOException {
PrintWriter os = createMock(PrintWriter.class);
expect(response.getWriter()).andReturn(os);
replay(response, os);
assertEquals(os, delegate.getWriter());
verify(response, os);
}
/**
* Test method for {@link MimeResponseDelegate#isResponseCommitted()}.
*/
@Test
public void testIsResponseCommitted() {
expect(response.isCommitted()).andReturn(true);
replay(response);
assertTrue(delegate.isResponseCommitted());
verify(response);
}
/**
* Test method for {@link MimeResponseDelegate#setContentType(String)}.
*/
@Test
public void testSetContentType() {
response.setContentType("text/html");
replay(response);
delegate.setContentType("text/html");
verify(response);
}
}
@@ -1,83 +0,0 @@
/*
* 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.tiles.request.portlet.delegate;
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletRequest;
import java.util.Map;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests {@link PortletRequestDelegate}.
*/
public class PortletRequestDelegateTest {
/**
* The request.
*/
private PortletRequest request;
/**
* The delegate to test.
*/
private PortletRequestDelegate delegate;
/**
* Sets up the test.
*/
@Before
public void setUp() {
request = createMock(PortletRequest.class);
delegate = new PortletRequestDelegate(request);
}
/**
* Test method for {@link PortletRequestDelegate#getParam()}.
*/
@Test
public void testGetParam() {
replay(request);
assertTrue(delegate.getParam() instanceof ReadOnlyEnumerationMap);
verify(request);
}
/**
* Test method for {@link PortletRequestDelegate#getParamValues()}.
*/
@Test
public void testGetParamValues() {
Map<String, String[]> params = createMock(Map.class);
expect(request.getParameterMap()).andReturn(params);
replay(request, params);
assertEquals(params, delegate.getParamValues());
verify(request, params);
}
}
@@ -1,106 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.ApplicationScopeExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletContext;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link ApplicationScopeExtractor}.
*/
public class ApplicationScopeExtractorTest {
/**
* The portlet context.
*/
private PortletContext context;
/**
* The extractot to test.
*/
private ApplicationScopeExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
context = createMock(PortletContext.class);
extractor = new ApplicationScopeExtractor(context);
}
/**
* Test method for {@link ApplicationScopeExtractor#setValue(String, Object)}.
*/
@Test
public void testSetValue() {
context.setAttribute("attribute", "value");
replay(context);
extractor.setValue("attribute", "value");
verify(context);
}
/**
* Test method for {@link ApplicationScopeExtractor#removeValue(String)}.
*/
@Test
public void testRemoveValue() {
context.removeAttribute("attribute");
replay(context);
extractor.removeValue("attribute");
verify(context);
}
/**
* Test method for {@link ApplicationScopeExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(context.getAttributeNames()).andReturn(keys);
replay(context, keys);
assertEquals(keys, extractor.getKeys());
verify(context, keys);
}
/**
* Test method for {@link ApplicationScopeExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(context.getAttribute("attribute")).andReturn("value");
replay(context);
assertEquals("value", extractor.getValue("attribute"));
verify(context);
}
}
@@ -1,117 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link HeaderExtractor}.
*/
public class HeaderExtractorTest {
/**
* The request.
*/
private PortletRequest request;
/**
* The response.
*/
private PortletResponse response;
/**
* The extractor to test.
*/
private HeaderExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
request = createMock(PortletRequest.class);
response = createMock(PortletResponse.class);
extractor = new HeaderExtractor(request, response);
}
/**
* Test method for {@link HeaderExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(request.getPropertyNames()).andReturn(keys);
replay(request, response, keys);
assertEquals(keys, extractor.getKeys());
verify(request, response, keys);
}
/**
* Test method for {@link HeaderExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(request.getProperty("name")).andReturn("value");
replay(request, response);
assertEquals("value", extractor.getValue("name"));
verify(request, response);
}
/**
* Test method for {@link HeaderExtractor#getValues(String)}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetValues() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(request.getProperties("name")).andReturn(keys);
replay(request, response, keys);
assertEquals(keys, extractor.getValues("name"));
verify(request, response, keys);
}
/**
* Test method for {@link HeaderExtractor#setValue(String, String)}.
*/
@Test
public void testSetValue() {
response.setProperty("name", "value");
replay(request, response);
extractor.setValue("name", "value");
verify(request, response);
}
}
@@ -1,83 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.InitParameterExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletContext;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link InitParameterExtractor}.
*/
public class InitParameterExtractorTest {
/**
* The portlet context.
*/
private PortletContext context;
/**
* The extractor to test.
*/
private InitParameterExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
context = createMock(PortletContext.class);
extractor = new InitParameterExtractor(context);
}
/**
* Test method for {@link InitParameterExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(context.getInitParameterNames()).andReturn(keys);
replay(context, keys);
assertEquals(keys, extractor.getKeys());
verify(context, keys);
}
/**
* Test method for {@link InitParameterExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(context.getInitParameter("name")).andReturn("value");
replay(context);
assertEquals("value", extractor.getValue("name"));
verify(context);
}
}
@@ -1,83 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletRequest;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link ParameterExtractor}.
*/
public class ParameterExtractorTest {
/**
* The request.
*/
private PortletRequest request;
/**
* The extractor to test.
*/
private ParameterExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
request = createMock(PortletRequest.class);
extractor = new ParameterExtractor(request);
}
/**
* Test method for {@link ParameterExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(request.getParameterNames()).andReturn(keys);
replay(request, keys);
assertEquals(keys, extractor.getKeys());
verify(request, keys);
}
/**
* Test method for {@link ParameterExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(request.getParameter("name")).andReturn("value");
replay(request);
assertEquals("value", extractor.getValue("name"));
verify(request);
}
}
@@ -1,107 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.RequestScopeExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletRequest;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link RequestScopeExtractor}.
*/
public class RequestScopeExtractorTest {
/**
* The request to test.
*/
private PortletRequest request;
/**
* The extractor to test.
*/
private RequestScopeExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
request = createMock(PortletRequest.class);
extractor = new RequestScopeExtractor(request);
}
/**
* Test method for {@link RequestScopeExtractor#setValue(String, Object)}.
*/
@Test
public void testSetValue() {
request.setAttribute("name", "value");
replay(request);
extractor.setValue("name", "value");
verify(request);
}
/**
* Test method for {@link RequestScopeExtractor#removeValue(String)}.
*/
@Test
public void testRemoveValue() {
request.removeAttribute("name");
replay(request);
extractor.removeValue("name");
verify(request);
}
/**
* Test method for {@link RequestScopeExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(request.getAttributeNames()).andReturn(keys);
replay(request, keys);
assertEquals(keys, extractor.getKeys());
verify(request, keys);
}
/**
* Test method for {@link RequestScopeExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(request.getAttribute("name")).andReturn("value");
replay(request);
assertEquals("value", extractor.getValue("name"));
verify(request);
}
}
@@ -1,154 +0,0 @@
/*
* 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.tiles.request.portlet.extractor;
import org.apache.tiles.request.portlet.extractor.SessionScopeExtractor;
import org.junit.Before;
import org.junit.Test;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import java.util.Enumeration;
import static org.easymock.EasyMock.*;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/**
* Tests {@link SessionScopeExtractor}.
*/
public class SessionScopeExtractorTest {
/**
* The request.
*/
private PortletRequest request;
/**
* The session.
*/
private PortletSession session;
/**
* The scope to test.
*/
private SessionScopeExtractor extractor;
/**
* Sets up the test.
*/
@Before
public void setUp() {
request = createMock(PortletRequest.class);
session = createMock(PortletSession.class);
extractor = new SessionScopeExtractor(request, PortletSession.PORTLET_SCOPE);
}
/**
* Tests {@link SessionScopeExtractor#SessionScopeExtractor(PortletRequest, int)}.
*/
@Test(expected = IllegalArgumentException.class)
public void testIllegalScope() {
replay(request, session);
new SessionScopeExtractor(request, 0);
verify(request, session);
}
/**
* Test method for {@link SessionScopeExtractor#setValue(String, Object)}.
*/
@Test
public void testSetValue() {
expect(request.getPortletSession()).andReturn(session);
session.setAttribute("name", "value", PortletSession.PORTLET_SCOPE);
replay(request, session);
extractor.setValue("name", "value");
verify(request, session);
}
/**
* Test method for {@link SessionScopeExtractor#removeValue(String)}.
*/
@Test
public void testRemoveValue() {
expect(request.getPortletSession(false)).andReturn(session);
session.removeAttribute("name", PortletSession.PORTLET_SCOPE);
replay(request, session);
extractor.removeValue("name");
verify(request, session);
}
/**
* Test method for {@link SessionScopeExtractor#getKeys()}.
*/
@SuppressWarnings("unchecked")
@Test
public void testGetKeys() {
Enumeration<String> keys = createMock(Enumeration.class);
expect(request.getPortletSession(false)).andReturn(session);
expect(session.getAttributeNames(PortletSession.PORTLET_SCOPE)).andReturn(keys);
replay(request, session, keys);
assertEquals(keys, extractor.getKeys());
verify(request, session, keys);
}
/**
* Test method for {@link SessionScopeExtractor#getKeys()}.
*/
@Test
public void testGetKeysNoSession() {
expect(request.getPortletSession(false)).andReturn(null);
replay(request, session);
assertNull(extractor.getKeys());
verify(request, session);
}
/**
* Test method for {@link SessionScopeExtractor#getValue(String)}.
*/
@Test
public void testGetValue() {
expect(request.getPortletSession(false)).andReturn(session);
expect(session.getAttribute("name", PortletSession.PORTLET_SCOPE)).andReturn("value");
replay(request, session);
assertEquals("value", extractor.getValue("name"));
verify(request, session);
}
/**
* Test method for {@link SessionScopeExtractor#getValue(String)}.
*/
@Test
public void testGetValueNoSession() {
expect(request.getPortletSession(false)).andReturn(null);
replay(request, session);
assertNull(extractor.getValue("name"));
verify(request, session);
}
}

Some files were not shown because too many files have changed in this diff Show More