Skip to content

Commit

Permalink
WW-5219 Moves TestNG related classes into TestNG plugin
Browse files Browse the repository at this point in the history
Also moves test classes under testng package
  • Loading branch information
lukaszlenart committed Sep 4, 2022
1 parent 49240c5 commit 5a3d2c4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 41 deletions.
3 changes: 1 addition & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>compile</scope>
<optional>true</optional>
<scope>test</scope>
</dependency>

<!-- SLF4J support -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion plugins/testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,8 +26,6 @@
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
Expand All @@ -39,7 +37,7 @@ protected void setUp() throws Exception {
super.setUp();
initDispatcher(null);
}

protected Dispatcher initDispatcher(Map<String,String> params) {
Dispatcher du = StrutsTestCaseHelper.initDispatcher(new MockServletContext(), params);
configurationManager = du.getConfigurationManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,13 +47,13 @@ public void testSimpleTest() throws Exception {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,12 +43,12 @@ public void testSimpleTest() throws Exception {
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;
Expand Down
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 5a3d2c4

Please sign in to comment.