mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
WW-5219 Moves TestNG related classes into TestNG plugin
Also moves test classes under testng package
This commit is contained in:
+1
-2
@@ -339,8 +339,7 @@
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- SLF4J support -->
|
||||
|
||||
+20
-23
@@ -18,53 +18,50 @@
|
||||
*/
|
||||
package org.apache.struts2.dispatcher.multipart;
|
||||
|
||||
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 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;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.struts2.dispatcher.LocalizedMessage;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.mock.web.DelegatingServletInputStream;
|
||||
import org.testng.Assert;
|
||||
|
||||
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();
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.9.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
||||
+2
-4
@@ -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();
|
||||
+2
-1
@@ -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;
|
||||
+5
-4
@@ -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;
|
||||
+4
-3
@@ -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;
|
||||
Reference in New Issue
Block a user