Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert PR 680 and also Ignore the challenged test #757

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tck/tck-docs/TCK-Exclude-List.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
# This is intended only for documentation purpose and is not used to exclude any tests.
# The tests are excluded from the test source using @Disabled tag in JUnit framework.
#
#servlet/tck/tck-runtime/src/main/java/servlet/tck/spec/httpservletresponse/HttpServletResponseTests.flushBufferTest()
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class HttpServletResponseTests extends AbstractTckTest {
Expand Down Expand Up @@ -70,55 +71,20 @@ public void intHeaderTest() throws Exception {
}

/*
* @testName: flushBufferOnContentLengthTest
* @testName: flushBufferTest
*
* @assertion_ids: Servlet:SPEC:32; Servlet:SPEC:33; Servlet:SPEC:42.2;
*
* @test_Strategy: 1. First call setContentLength to set the length of
* content; 2. Write bytes to the expected content length; 3. Call
* setIntHeader to set header; 4. Attempt to write
* additional bytes, expecting an exception to confirm the output stream
* is closed; 5. Verify a 200 response without the header value set.
* 6. Repeat the test to check that the expected exception was thrown
* after the first request.
* content; 2. Then write to the buffer to fill up the buffer. 2. Call
* setIntHeader to set header 3. Verify that the header value is not set,
*/
@Disabled
@Test
public void flushBufferOnContentLengthTest() throws Exception {
TEST_PROPS.get().setProperty(SAVE_STATE, "true");
public void flushBufferTest() throws Exception {
TEST_PROPS.get().setProperty(UNEXPECTED_HEADERS, "header1: 12345");
TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/"
+ getServletName() + "?testname=" + "flushBufferOnContentLengthTest" + " HTTP/1.1");
invoke();

TEST_PROPS.get().setProperty(USE_SAVED_STATE, "true");
TEST_PROPS.get().setProperty(UNEXPECTED_HEADERS, "header1: 12345");
TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/"
+ getServletName() + "?testname=" + "flushBufferOnContentLengthTest" + " HTTP/1.1");
invoke();
}

/*
* @testName: flushBufferOnContentLengthCommittedTest
*
* @assertion_ids: Servlet:SPEC:32; Servlet:SPEC:33; Servlet:SPEC:42.2;
*
* @test_Strategy: 1. First call setContentLength to set the length of
* content; 2. Write some bytes and flush the response; 3. Write
* remaining bytes to the expected content length; 4. Attempt to write
* additional bytes, expecting an exception to confirm the output stream
* is closed; 5. Verify a 200 response; 6. Repeat the test to check that
* the expected exception was thrown after the first request.
*/
@Test
public void flushBufferOnContentLengthCommittedTest() throws Exception {
TEST_PROPS.get().setProperty(SAVE_STATE, "true");
TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/"
+ getServletName() + "?testname=" + "flushBufferOnContentLengthCommittedTest" + " HTTP/1.1");
invoke();

TEST_PROPS.get().setProperty(USE_SAVED_STATE, "true");
TEST_PROPS.get().setProperty(REQUEST, "GET " + getContextRoot() + "/"
+ getServletName() + "?testname=" + "flushBufferOnContentLengthCommittedTest" + " HTTP/1.1");
+ getServletName() + "?testname=" + "flushBufferTest" + " HTTP/1.1");
invoke();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
package servlet.tck.spec.httpservletresponse;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import jakarta.servlet.http.HttpSession;
import servlet.tck.common.servlets.HttpTCKServlet;

import jakarta.servlet.ServletException;
Expand All @@ -46,54 +42,22 @@ public void intHeaderTest(HttpServletRequest request,
response.addIntHeader("header2", 56789);
}

public void flushBufferOnContentLengthTest(HttpServletRequest request,
public void flushBufferTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
Object illegalStateException = session.getAttribute("IllegalStateException");
if (illegalStateException instanceof IllegalStateException)
throw (IllegalStateException)illegalStateException;

int size = 40;
response.setContentLength(size);

OutputStream out = response.getOutputStream();
byte[] passed = "Test PASSED\n".getBytes(StandardCharsets.ISO_8859_1);
out.write(passed);

byte[] fill = new byte[size - passed.length];
Arrays.fill(fill, (byte) 'x');
out.write(fill);
PrintWriter pw = response.getWriter();
pw.println("Test PASSED");
StringBuffer tmp = new StringBuffer(2 * size);
int i = 0;

while (i < 8) {
tmp = tmp.append("111111111x");
i = i + 1;
}
pw.println(tmp);
response.addIntHeader("header1", 12345);

try {
out.write(fill);
session.setAttribute("IllegalStateException", new IllegalStateException("write did not fail"));
} catch (IOException ignored) {}
}

public void flushBufferOnContentLengthCommittedTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
Object illegalStateException = session.getAttribute("IllegalStateException");
if (illegalStateException instanceof IllegalStateException)
throw (IllegalStateException)illegalStateException;

int size = 40;
response.setContentLength(size);

OutputStream out = response.getOutputStream();
byte[] passed = "Test PASSED\n".getBytes(StandardCharsets.ISO_8859_1);
out.write(passed);
response.flushBuffer();

byte[] fill = new byte[size - passed.length];
Arrays.fill(fill, (byte) 'x');
out.write(fill);

try {
out.write(fill);
session.setAttribute("IllegalStateException", new IllegalStateException("write did not fail"));
} catch (IOException ignored) {}
}

public void sendErrorCommitTest(HttpServletRequest request,
Expand Down