Skip to content

Commit

Permalink
Revert PR 680 and also Ignore the challenged test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmd1nh committed Nov 11, 2024
1 parent 4a716d5 commit a52dcd3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 88 deletions.
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.Ignore;
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,
*/
@Ignore
@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

0 comments on commit a52dcd3

Please sign in to comment.