This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5219-move-testng in repository https://gitbox.apache.org/repos/asf/struts.git
commit 5a3d2c4eb9c8cf9ed74c53ab2c79c05868dc70c6 Author: Lukasz Lenart <[email protected]> AuthorDate: Sun Sep 4 11:15:28 2022 +0200 WW-5219 Moves TestNG related classes into TestNG plugin Also moves test classes under testng package --- core/pom.xml | 3 +- .../JakartaStreamMultiPartRequestTest.java | 43 ++++++++++------------ plugins/testng/pom.xml | 1 - .../struts2/{ => testng}/StrutsTestCase.java | 6 +-- .../struts2/testng}/TestNGXWorkTestCase.java | 3 +- .../{ => testng}/TestNGStrutsTestCaseTest.java | 9 +++-- .../struts2/testng}/TestNGXWorkTestCaseTest.java | 7 ++-- pom.xml | 4 +- 8 files changed, 35 insertions(+), 41 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d7cee0c16..71a3f777b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -339,8 +339,7 @@ <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <scope>compile</scope> - <optional>true</optional> + <scope>test</scope> </dependency> <!-- SLF4J support --> diff --git a/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequestTest.java b/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequestTest.java index cf453acac..59861e2ed 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequestTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/multipart/JakartaStreamMultiPartRequestTest.java @@ -18,53 +18,50 @@ */ package org.apache.struts2.dispatcher.multipart; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; - -import javax.servlet.http.HttpServletRequest; - import org.apache.struts2.dispatcher.LocalizedMessage; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.springframework.mock.web.DelegatingServletInputStream; -import org.testng.Assert; + +import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; public class JakartaStreamMultiPartRequestTest { private JakartaStreamMultiPartRequest multiPart; private Path tempDir; - + @Before public void initialize() { multiPart = new JakartaStreamMultiPartRequest(); tempDir = Paths.get("target", "multi-part-test"); } - + /** * Number of bytes in files greater than 2GB overflow the {@code int} primative. - * The {@link HttpServletRequest#getContentLength()} returns {@literal -1} + * The {@link HttpServletRequest#getContentLength()} returns {@literal -1} * when the header is not present or the size is greater than {@link Integer#MAX_VALUE}. - * @throws IOException */ @Test public void unknownContentLength() throws IOException { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getContentType()).thenReturn("multipart/form-data; charset=utf-8; boundary=__X_BOUNDARY__"); Mockito.when(request.getMethod()).thenReturn("POST"); - Mockito.when(request.getContentLength()).thenReturn(Integer.valueOf(-1)); - StringBuilder entity = new StringBuilder(); - entity.append("\r\n--__X_BOUNDARY__\r\n"); - entity.append("Content-Disposition: form-data; name=\"upload\"; filename=\"test.csv\"\r\n"); - entity.append("Content-Type: text/csv\r\n\r\n1,2\r\n\r\n"); - entity.append("--__X_BOUNDARY__\r\n"); - entity.append("Content-Disposition: form-data; name=\"upload2\"; filename=\"test2.csv\"\r\n"); - entity.append("Content-Type: text/csv\r\n\r\n3,4\r\n\r\n"); - entity.append("--__X_BOUNDARY__--\r\n"); - Mockito.when(request.getInputStream()).thenReturn(new DelegatingServletInputStream(new ByteArrayInputStream(entity.toString().getBytes(StandardCharsets.UTF_8)))); + Mockito.when(request.getContentLength()).thenReturn(-1); + String entity = "\r\n--__X_BOUNDARY__\r\n" + + "Content-Disposition: form-data; name=\"upload\"; filename=\"test.csv\"\r\n" + + "Content-Type: text/csv\r\n\r\n1,2\r\n\r\n" + + "--__X_BOUNDARY__\r\n" + + "Content-Disposition: form-data; name=\"upload2\"; filename=\"test2.csv\"\r\n" + + "Content-Type: text/csv\r\n\r\n3,4\r\n\r\n" + + "--__X_BOUNDARY__--\r\n"; + Mockito.when(request.getInputStream()).thenReturn(new DelegatingServletInputStream(new ByteArrayInputStream(entity.getBytes(StandardCharsets.UTF_8)))); multiPart.setMaxSize("4"); multiPart.parse(request, tempDir.toString()); LocalizedMessage next = multiPart.getErrors().iterator().next(); diff --git a/plugins/testng/pom.xml b/plugins/testng/pom.xml index 823941ba1..cc4d2ba51 100644 --- a/plugins/testng/pom.xml +++ b/plugins/testng/pom.xml @@ -35,7 +35,6 @@ <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <version>6.9.10</version> </dependency> <dependency> <groupId>org.springframework</groupId> diff --git a/plugins/testng/src/main/java/org/apache/struts2/StrutsTestCase.java b/plugins/testng/src/main/java/org/apache/struts2/testng/StrutsTestCase.java similarity index 96% rename from plugins/testng/src/main/java/org/apache/struts2/StrutsTestCase.java rename to plugins/testng/src/main/java/org/apache/struts2/testng/StrutsTestCase.java index 193f14220..630eb2df6 100644 --- a/plugins/testng/src/main/java/org/apache/struts2/StrutsTestCase.java +++ b/plugins/testng/src/main/java/org/apache/struts2/testng/StrutsTestCase.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.struts2; +package org.apache.struts2.testng; import java.util.Map; @@ -26,8 +26,6 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.springframework.mock.web.MockServletContext; -import com.opensymphony.xwork2.TestNGXWorkTestCase; - /** * Base test class for TestNG unit tests. Provides common Struts variables * and performs Struts setup and teardown processes @@ -39,7 +37,7 @@ public class StrutsTestCase extends TestNGXWorkTestCase { super.setUp(); initDispatcher(null); } - + protected Dispatcher initDispatcher(Map<String,String> params) { Dispatcher du = StrutsTestCaseHelper.initDispatcher(new MockServletContext(), params); configurationManager = du.getConfigurationManager(); diff --git a/core/src/main/java/com/opensymphony/xwork2/TestNGXWorkTestCase.java b/plugins/testng/src/main/java/org/apache/struts2/testng/TestNGXWorkTestCase.java similarity index 96% rename from core/src/main/java/com/opensymphony/xwork2/TestNGXWorkTestCase.java rename to plugins/testng/src/main/java/org/apache/struts2/testng/TestNGXWorkTestCase.java index 3f34dfec1..3d3519b3d 100644 --- a/core/src/main/java/com/opensymphony/xwork2/TestNGXWorkTestCase.java +++ b/plugins/testng/src/main/java/org/apache/struts2/testng/TestNGXWorkTestCase.java @@ -16,8 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package com.opensymphony.xwork2; +package org.apache.struts2.testng; +import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.config.ConfigurationProvider; diff --git a/plugins/testng/src/test/java/org/apache/struts2/TestNGStrutsTestCaseTest.java b/plugins/testng/src/test/java/org/apache/struts2/testng/TestNGStrutsTestCaseTest.java similarity index 95% rename from plugins/testng/src/test/java/org/apache/struts2/TestNGStrutsTestCaseTest.java rename to plugins/testng/src/test/java/org/apache/struts2/testng/TestNGStrutsTestCaseTest.java index dd4ab6a7a..cd86bf99c 100644 --- a/plugins/testng/src/test/java/org/apache/struts2/TestNGStrutsTestCaseTest.java +++ b/plugins/testng/src/test/java/org/apache/struts2/testng/TestNGStrutsTestCaseTest.java @@ -16,11 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.struts2; +package org.apache.struts2.testng; import junit.framework.TestCase; import org.apache.struts2.dispatcher.Dispatcher; +import org.apache.struts2.testng.StrutsTestCase; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -46,13 +47,13 @@ public class TestNGStrutsTestCaseTest extends TestCase { RunTest.mgr = null; } } - + public static class RunTest extends StrutsTestCase { public static boolean ran = false; public static ConfigurationManager mgr; public static Dispatcher du; - - @Test + + @Test public void testRun() { ran = true; mgr = this.configurationManager; diff --git a/core/src/test/java/com/opensymphony/xwork2/TestNGXWorkTestCaseTest.java b/plugins/testng/src/test/java/org/apache/struts2/testng/TestNGXWorkTestCaseTest.java similarity index 95% rename from core/src/test/java/com/opensymphony/xwork2/TestNGXWorkTestCaseTest.java rename to plugins/testng/src/test/java/org/apache/struts2/testng/TestNGXWorkTestCaseTest.java index 0b543a6a0..dcc7a8c9c 100644 --- a/core/src/test/java/com/opensymphony/xwork2/TestNGXWorkTestCaseTest.java +++ b/plugins/testng/src/test/java/org/apache/struts2/testng/TestNGXWorkTestCaseTest.java @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package com.opensymphony.xwork2; +package org.apache.struts2.testng; import com.opensymphony.xwork2.config.ConfigurationManager; import junit.framework.TestCase; +import org.apache.struts2.testng.TestNGXWorkTestCase; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -42,12 +43,12 @@ public class TestNGXWorkTestCaseTest extends TestCase { RunTest.mgr = null; } } - + @Test public static class RunTest extends TestNGXWorkTestCase { public static boolean ran = false; public static ConfigurationManager mgr; - + public void testRun() { ran = true; mgr = this.configurationManager; diff --git a/pom.xml b/pom.xml index cdd13feda..1899ed558 100644 --- a/pom.xml +++ b/pom.xml @@ -1112,9 +1112,7 @@ <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> - <version>7.1.0</version> - <scope>compile</scope> - <optional>true</optional> + <version>7.4.0</version> </dependency> <dependency>
