Skip to content

Commit

Permalink
Added additional testing including regular expression and made small …
Browse files Browse the repository at this point in the history
…change to clarify javadoc from code review.
  • Loading branch information
jim-krueger committed Mar 20, 2024
1 parent 510ca53 commit 7a89e78
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ public default boolean hasProperty(String name) {
* (missing comma), or the value {@code no - store} (whitespace within value).
*
* @param name the message header.
* @param valueSeparatorRegex Separates the header value into single values. {@code null} does not split.
* @param valueSeparatorRegex String or regular expression that separates the header value into single values.
* {@code null} does not split.
* @param valuePredicate value must fulfil this predicate.
* @return {@code true} if and only if a header with the given name exists, having either a whitespace-trimmed value
* matching the predicate, or having at least one whitespace-trimmed single value in a token-separated list of single values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public interface ClientResponseContext {
* (missing comma), or the value {@code no - store} (whitespace within value).
*
* @param name the message header.
* @param valueSeparatorRegex Separates the header value into single values. {@code null} does not split.
* @param valueSeparatorRegex String or regular expression that separates the header value into single values.
* {@code null} does not split.
* @param valuePredicate value must fulfil this predicate.
* @return {@code true} if and only if a header with the given name exists, having either a whitespace-trimmed value
* matching the predicate, or having at least one whitespace-trimmed single value in a token-separated list of single values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package ee.jakarta.tck.ws.rs.api.client.clientrequestcontext;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.io.ByteArrayInputStream;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -874,22 +875,31 @@ public void containsHeaderStringTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
assertTrue(context.containsHeaderString("cache-control", "no-store"::equalsIgnoreCase));
assertTrue(context.containsHeaderString("CACHE-CONTROL", ",", "no-transform"::equalsIgnoreCase));
assertTrue(!(context.containsHeaderString("CACHE-CONTROL", ",", "Max-Age"::equalsIgnoreCase)));
assertTrue(!(context.containsHeaderString("cache-control", ",", "no-transform"::equals)));
assertTrue(context.containsHeaderString("cache-control2", ";", "no-transform"::equalsIgnoreCase));
assertTrue(!(context.containsHeaderString("cache-control2", ",",
"no-transform"::equalsIgnoreCase)));
assertTrue(context.containsHeaderString("header1", "value"::equalsIgnoreCase));
assertTrue(context.containsHeaderString("HEADER1", ",", "value2"::equals));
//Incorrect separator character
assertFalse(context.containsHeaderString("header1", ";", "value2"::equalsIgnoreCase));
//Shouldn't find first value when separator character is incorrect
assertFalse(context.containsHeaderString("header1", ";", "value1"::equalsIgnoreCase));
//Test regular expression
assertFalse(context.containsHeaderString("header1", "; | ,", "value2"::equalsIgnoreCase));
//White space in value not trimmed
assertFalse(context.containsHeaderString("header1", "whitespace"::equalsIgnoreCase));
//Multiple character separator
assertTrue(context.containsHeaderString("header2", "::", "Value5"::equalsIgnoreCase));
//Test default separator is comma
assertFalse(context.containsHeaderString("header3","value6"::equalsIgnoreCase));
String entity = "Success";
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider)
.header("cache-control", "no-store")
.header("cache-control", "{Max - Age, no-transform}")
.header("cache-control2", "{no-store;no-transform}")
.header("header1", "value")
.header("header1", "{value1 , value2}")
.header("header1", "{Value3,white space} ")
.header("header2", "{Value4::Value5")
.header("header3", "{value6;value7}")
.buildGet();
Response response = invoke(invocation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package ee.jakarta.tck.ws.rs.api.client.clientresponsecontext;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.BufferedReader;
Expand Down Expand Up @@ -437,7 +438,7 @@ protected void checkFilterContext(ClientRequestContext requestContext,
*/
@Test
public void containsHeaderStringTest() throws Fault {
final String header1 = "cache-control";
final String header1 = "Header1";
final String value1 = "no-store";
final String value2 = "{Max - Age, no-transform}";
final String header2 = "header2";
Expand All @@ -447,18 +448,28 @@ public void containsHeaderStringTest() throws Fault {
@Override
protected void checkFilterContext(ClientRequestContext requestContext,
ClientResponseContext responseContext) throws Fault {
assertTrue(responseContext.containsHeaderString("cache-control", "no-store"::equalsIgnoreCase));
assertTrue(responseContext.containsHeaderString("CACHE-CONTROL", ",", "no-transform"::equalsIgnoreCase));
assertTrue(!(responseContext.containsHeaderString("CACHE-CONTROL", ",", "Max-Age"::equalsIgnoreCase)));
assertTrue(!(responseContext.containsHeaderString("cache-control", ",", "no-transform"::equals)));
assertTrue(responseContext.containsHeaderString("header2", ";", "no-transform"::equalsIgnoreCase));
assertTrue(!(responseContext.containsHeaderString("Header2", ",", "no-transform"::equalsIgnoreCase)));
assertTrue(responseContext.containsHeaderString("header1", "value"::equalsIgnoreCase));
assertTrue(responseContext.containsHeaderString("HEADER1", ",", "value2"::equals));
//Incorrect separator character
assertFalse(responseContext.containsHeaderString("header1", ";", "value2"::equalsIgnoreCase));
//Shouldn't find first value when separator character is incorrect
assertFalse(responseContext.containsHeaderString("header1", ";", "value1"::equalsIgnoreCase));
//Test regular expression
assertFalse(responseContext.containsHeaderString("header1", "; | ,", "value2"::equalsIgnoreCase));
//White space in value not trimmed
assertFalse(responseContext.containsHeaderString("header1", "whitespace"::equalsIgnoreCase));
//Multiple character separator
assertTrue(responseContext.containsHeaderString("header2", "::", "Value5"::equalsIgnoreCase));
//Test default separator is comma
assertFalse(responseContext.containsHeaderString("header3","value6"::equalsIgnoreCase));
}
};
Response response = Response.ok()
.header(header1, value1)
.header(header1, value2)
.header(header2, value3)
.header("header1", "value")
.header("header1", "{value1 , value2}")
.header("header1", "{Value3,white space} ")
.header("header2", "{Value4::Value5")
.header("header3", "{value6;value7}")
.build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Expand Down

0 comments on commit 7a89e78

Please sign in to comment.