Merge pull request #1238 from jim-krueger/1227-TCK-containsHeaderString
Add tests for containsHeaderString
diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java b/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java
index 6bf01a0..51060ef 100644
--- a/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java
+++ b/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -207,7 +207,8 @@
* (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 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.
diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientResponseContext.java b/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientResponseContext.java
index 756e428..5169f96 100644
--- a/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientResponseContext.java
+++ b/jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientResponseContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -99,7 +99,8 @@
* (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 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.
diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerRequestContext.java b/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerRequestContext.java
index 9d05bbe..bc91257 100644
--- a/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerRequestContext.java
+++ b/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerRequestContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -239,7 +239,7 @@
* (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 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.
diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerResponseContext.java b/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerResponseContext.java
index 6d6b744..f1e1562 100644
--- a/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerResponseContext.java
+++ b/jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerResponseContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -129,7 +129,7 @@
* (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 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.
diff --git a/jaxrs-api/src/main/java/jakarta/ws/rs/core/HttpHeaders.java b/jaxrs-api/src/main/java/jakarta/ws/rs/core/HttpHeaders.java
index 84cdd4c..0506be4 100644
--- a/jaxrs-api/src/main/java/jakarta/ws/rs/core/HttpHeaders.java
+++ b/jaxrs-api/src/main/java/jakarta/ws/rs/core/HttpHeaders.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -75,7 +75,8 @@
* (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 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.
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientrequestcontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientrequestcontext/JAXRSClientIT.java
index 0cf291d..2b958c6 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientrequestcontext/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientrequestcontext/JAXRSClientIT.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -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;
@@ -861,6 +862,46 @@
}
/*
+ * @testName: containsHeaderStringTest
+ *
+ * @assertion_ids: JAXRS:JAVADOC:1353; JAXRS:JAVADOC:1354;
+ *
+ * @test_Strategy: Check if the specified header contains a specified value.
+ *
+ * ClientRequestFilter.abortWith
+ */
+ @Test
+ public void containsHeaderStringTest() throws Fault {
+ ContextProvider provider = new ContextProvider() {
+ @Override
+ protected void checkFilterContext(ClientRequestContext context) throws Fault {
+ assertTrue(context.containsHeaderString("header1", "value"::equals));
+ assertTrue(context.containsHeaderString("HEADER1", ",", "value2"::equals));
+ //Incorrect separator character
+ assertFalse(context.containsHeaderString("header1", ";", "value2"::equals));
+ //Shouldn't find first value when separator character is incorrect
+ assertFalse(context.containsHeaderString("header1", ";", "Value1"::equalsIgnoreCase));
+ //Test regular expression
+ assertTrue(context.containsHeaderString("header1", ";|,", "VALUE2"::equalsIgnoreCase));
+ //White space in value not trimmed
+ assertFalse(context.containsHeaderString("header1", "whitespace"::equals));
+ //Multiple character separator
+ assertTrue(context.containsHeaderString("header2", ";;", "Value5"::equalsIgnoreCase));
+ Response r = Response.ok().build();
+ context.abortWith(r);
+ }
+ };
+ Invocation invocation = buildBuilder(provider)
+ .header("header1", "value")
+ .header("header1", "value1 , value2")
+ .header("header1", "Value3,white space ")
+ .header("header2", "Value4;;Value5")
+ .buildGet();
+ Response response = invoke(invocation);
+ }
+
+
+ /*
* @testName: getHeaderStringTest
*
* @assertion_ids: JAXRS:JAVADOC:440; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientresponsecontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientresponsecontext/JAXRSClientIT.java
index 4b4d5d4..bcce831 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientresponsecontext/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/api/client/clientresponsecontext/JAXRSClientIT.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -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;
@@ -427,6 +428,47 @@
}
/*
+ * @testName: containsHeaderStringTest
+ *
+ * @assertion_ids: JAXRS:JAVADOC:1355; JAXRS:JAVADOC:1356;
+ *
+ * @test_Strategy: Check if the specified header contains a specified value.
+ *
+ * ClientRequestFilter.abortWith
+ */
+ @Test
+ public void containsHeaderStringTest() throws Fault {
+
+ ContextProvider in = new ContextProvider() {
+ @Override
+ protected void checkFilterContext(ClientRequestContext requestContext,
+ ClientResponseContext responseContext) throws Fault {
+ assertTrue(responseContext.containsHeaderString("header1", "value"::equals));
+ assertTrue(responseContext.containsHeaderString("HEADER1", ",", "value2"::equals));
+ //Incorrect separator character
+ assertFalse(responseContext.containsHeaderString("header1", ";", "value2"::equals));
+ //Shouldn't find first value when separator character is incorrect
+ assertFalse(responseContext.containsHeaderString("header1", ";", "Value1"::equalsIgnoreCase));
+ //Test regular expression
+ assertTrue(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));
+ }
+ };
+ Response response = Response.ok()
+ .header("header1", "value")
+ .header("header1", "value1 , value2")
+ .header("header1", "Value3,white space ")
+ .header("header2", "Value4;;Value5")
+ .build();
+ invokeWithResponseAndAssertStatus(response, Status.OK, in);
+ }
+
+
+
+ /*
* @testName: getLanguageTest
*
* @assertion_ids: JAXRS:JAVADOC:464; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/ContextOperation.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/ContextOperation.java
index bace618..60c4e9b 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/ContextOperation.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/ContextOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,5 +17,5 @@
package ee.jakarta.tck.ws.rs.ee.rs.container.requestcontext;
public enum ContextOperation {
- ABORTWITH, GETACCEPTABLELANGUAGES, GETACCEPTABLELANGUAGESISREADONLY, GETACCEPTABLEMEDIATYPES, GETACCEPTABLEMEDIATYPESISREADONLY, GETCOOKIES, GETCOOKIESISREADONLY, GETDATE, GETENTITYSTREAM, GETHEADERS, GETHEADERSISMUTABLE, GETHEADERSTRING2, GETLANGUAGE, GETLENGTH, GETMEDIATYPE, GETMETHOD, GETPROPERTY, GETPROPERTYNAMES, GETPROPERTYNAMESISREADONLY, GETREQUEST, GETSECURITYCONTEXT, GETURIINFO, HASENTITY, REMOVEPROPERTY, SETENTITYSTREAM, SETMETHOD, SETPROPERTY, SETPROPERTYNULL, SETPROPERTYCONTEXT, SETREQUESTURI1, SETREQUESTURI2, SETSECURITYCONTEXT;
+ ABORTWITH, GETACCEPTABLELANGUAGES, GETACCEPTABLELANGUAGESISREADONLY, GETACCEPTABLEMEDIATYPES, GETACCEPTABLEMEDIATYPESISREADONLY, GETCOOKIES, GETCOOKIESISREADONLY, GETDATE, GETENTITYSTREAM, CONTAINSHEADERSTRING, GETHEADERS, GETHEADERSISMUTABLE, GETHEADERSTRING2, GETLANGUAGE, GETLENGTH, GETMEDIATYPE, GETMETHOD, GETPROPERTY, GETPROPERTYNAMES, GETPROPERTYNAMESISREADONLY, GETREQUEST, GETSECURITYCONTEXT, GETURIINFO, HASENTITY, REMOVEPROPERTY, SETENTITYSTREAM, SETMETHOD, SETPROPERTY, SETPROPERTYNULL, SETPROPERTYCONTEXT, SETREQUESTURI1, SETREQUESTURI2, SETSECURITYCONTEXT;
}
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/JAXRSClientIT.java
index dc3d48a..4b215b6 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/JAXRSClientIT.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -334,6 +334,34 @@
}
/*
+ * @testName: containsHeaderStringTest
+ *
+ * @assertion_ids: JAXRS:JAVADOC:JAXRS:JAVADOC:1359; JAXRS:JAVADOC:1360
+ *
+ * @test_Strategy: Check if the specified header contains a specified value.
+ *
+ * Filter method called before a request has been dispatched to a resource.
+ * Throws IOException.
+ */
+ @Test
+ @Tag("servlet")
+ public void containsHeaderStringTest() throws Fault {
+ setProperty(Property.REQUEST_HEADERS,
+ "Accept:text/*, text/html, text/html;level=1, */*");
+ setProperty(Property.REQUEST_HEADERS,
+ "Content-Type:application/xml;charset=utf8");
+ setProperty(Property.REQUEST_HEADERS,
+ "Header3:value1 ;; Value2 ;;value 3");
+ setProperty(Property.SEARCH_STRING, "Test1");
+ setProperty(Property.SEARCH_STRING, "Test2");
+ setProperty(Property.SEARCH_STRING, "Test3");
+ setProperty(Property.SEARCH_STRING, "Test4");
+ setProperty(Property.SEARCH_STRING, "Test5");
+
+ invokeRequestAndCheckResponse(ContextOperation.CONTAINSHEADERSTRING);
+ }
+
+ /*
* @testName: getHeadersTest
*
* @assertion_ids: JAXRS:JAVADOC:655; JAXRS:JAVADOC:677; JAXRS:JAVADOC:678;
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/RequestFilter.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/RequestFilter.java
index c0cc756..3607f57 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/RequestFilter.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/requestcontext/RequestFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -140,6 +140,37 @@
abortWithEntity(entity);
}
+ public void containsHeaderString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("containsHeaderString= ");
+
+ try {
+ assertTrue(requestContext.containsHeaderString("accept", "text/html"::equals));
+ sb.append("Test1: accept contains text/html; ");
+
+ //Verify Predicate and separator character usage
+ assertTrue(requestContext.containsHeaderString("Accept", ",", "Text/html;Level=1"::equalsIgnoreCase));
+ sb.append("Test2: accept contains text/html;level=1; ");
+
+ //Verify incorrect separator character fails
+ assertTrue(!(requestContext.containsHeaderString("Accept", ";", "text/html;level=1"::equals)));
+ sb.append("Test3: Incorrect separator character fails as expected; ");
+
+ //Verify white space in value not trimmed and double character separator
+ assertTrue(!(requestContext.containsHeaderString("header3", ";;", "value3"::equals)));
+ sb.append("Test4: White space not trimmed from value as expected; ");
+
+ //Verify white space in front and back of value trimmed
+ assertTrue(requestContext.containsHeaderString("HEADER3", ";;", "value2"::equalsIgnoreCase));
+ sb.append("Test5: White space trimmed around value as expected; ");
+ } catch (Throwable ex) {
+ sb.append("Unexpected exception thrown in containsHeaderString: "
+ + ex.getMessage());
+ ex.printStackTrace();
+ }
+ abortWithEntity(sb.toString());
+ }
+
public void getHeaders() {
MultivaluedMap<String, String> headers = requestContext.getHeaders();
StringBuilder sb = new StringBuilder();
@@ -149,7 +180,7 @@
}
abortWithEntity(sb.toString());
}
-
+
public void getHeadersIsMutable() {
String key = "KEY";
MultivaluedMap<String, String> headers = requestContext.getHeaders();
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ContextOperation.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ContextOperation.java
index 057e978..8778fa0 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ContextOperation.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ContextOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,7 +17,7 @@
package ee.jakarta.tck.ws.rs.ee.rs.container.responsecontext;
public enum ContextOperation {
- GETALLOWEDMETHODS, GETCOOKIES, GETCOOKIESISREADONLY, GETDATE, GETENTITY, GETENTITYANNOTATIONS, GETENTITYANNOTATIONSONENTITY, GETENTITYCLASS, GETENTITYSTREAM, GETENTITYTAG, GETENTITYTYPE, GETHEADERS, GETHEADERSISMUTABLE, GETHEADERSTRINGOPERATION, GETHEADERSTRINGHEADER, GETLANGUAGE, GETLASTMODIFIED, GETLENGTH, GETLINK, GETLINKBUILDER, GETLINKS, GETLOCATION, GETMEDIATYPE, GETSTATUS, GETSTATUSINFO, GETSTRINGHEADERS, HASENTITY, HASLINK, SETENTITY, SETENTITYSTREAM, SETSTATUS, SETSTATUSINFO,
+ GETALLOWEDMETHODS, GETCOOKIES, GETCOOKIESISREADONLY, GETDATE, GETENTITY, GETENTITYANNOTATIONS, GETENTITYANNOTATIONSONENTITY, GETENTITYCLASS, GETENTITYSTREAM, GETENTITYTAG, GETENTITYTYPE, CONTAINSHEADERSTRING, GETHEADERS, GETHEADERSISMUTABLE, GETHEADERSTRINGOPERATION, GETHEADERSTRINGHEADER, GETLANGUAGE, GETLASTMODIFIED, GETLENGTH, GETLINK, GETLINKBUILDER, GETLINKS, GETLOCATION, GETMEDIATYPE, GETSTATUS, GETSTATUSINFO, GETSTRINGHEADERS, HASENTITY, HASLINK, SETENTITY, SETENTITYSTREAM, SETSTATUS, SETSTATUSINFO,
// just helping methods, pass
SETSTRINGBEANRUNTIME, SETORIGINALRUNTIME
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java
index c40db3f..416e1ca 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/JAXRSClientIT.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -448,6 +448,25 @@
/*
* @testName: getHeadersTest
*
+ * @assertion_ids: JAXRS:JAVADOC:1357; JAXRS:JAVADOC:1358;
+ *
+ * @test_Strategy: Get the mutable response headers multivalued map.
+ *
+ * Filter method called after a response has been provided for a request.
+ * Throws IOException.
+ */
+ @Test
+ public void containsHeaderStringTest() throws Fault {
+ String header = "Test";
+ for (int i = 1; i != 6; i++)
+ setProperty(Property.UNORDERED_SEARCH_STRING, header + i);
+ setProperty(Property.CONTENT, header);
+ invokeRequestAndCheckResponse(ContextOperation.CONTAINSHEADERSTRING);
+ }
+
+ /*
+ * @testName: getHeadersTest
+ *
* @assertion_ids: JAXRS:JAVADOC:688; JAXRS:JAVADOC:707; JAXRS:JAVADOC:708;
*
* @test_Strategy: Get the mutable response headers multivalued map.
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/Resource.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/Resource.java
index dc0cef1..f8effbe 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/Resource.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/Resource.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -180,6 +180,17 @@
}
@POST
+ @Path("containsheaderstring")
+ public Response containsHeaderString(String header) {
+ ResponseBuilder builder = createResponseWithHeader();
+ builder = builder.header("Accept", "text/html, text/html;level=1, */*");
+ builder = builder.header("Content-Type", "application/xml;charset=utf8");
+ builder = builder.header("Header3", "value1 ;; Value2 ;;value 3");
+ Response response = builder.build();
+ return response;
+ }
+
+ @POST
@Path("getheaders")
public Response getHeaders(String header) {
ResponseBuilder builder = createResponseWithHeader();
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java
index 7c7c3c9..5b816b5 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/container/responsecontext/ResponseFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -152,6 +152,37 @@
setEntity(name);
}
+ public void containsHeaderString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("containsHeaderString= ");
+
+ try {
+ assertTrue(responseContext.containsHeaderString("accept", "text/html"::equals));
+ sb.append("Test1: accept contains text/html; ");
+
+ //Verify Predicate and separator character usage
+ assertTrue(responseContext.containsHeaderString("Accept", ",", "Text/html;Level=1"::equalsIgnoreCase));
+ sb.append("Test2: accept contains text/html;level=1; ");
+
+ //Verify incorrect separator character fails
+ assertTrue(!(responseContext.containsHeaderString("Accept", ";", "text/html;level=1"::equals)));
+ sb.append("Test3: Incorrect separator character fails as expected; ");
+
+ //Verify white space in value not trimmed and double character separator
+ assertTrue(!(responseContext.containsHeaderString("header3", ";;", "value3"::equals)));
+ sb.append("Test4: White space not trimmed from value as expected; ");
+
+ //Verify white space in front and back of value trimmed
+ assertTrue(responseContext.containsHeaderString("HEADER3", ";;", "value2"::equalsIgnoreCase));
+ sb.append("Test5: White space trimmed around value as expected; ");
+ } catch (Throwable ex) {
+ sb.append("Unexpected exception thrown in containsHeaderString: "
+ + ex.getMessage());
+ ex.printStackTrace();
+ }
+ setEntity(sb.toString());
+ }
+
public void getHeaders() {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
setEntity(collectionToString(headers.keySet()));
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/HttpHeadersTest.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/HttpHeadersTest.java
index 72df7b6..7a60b23 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/HttpHeadersTest.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/HttpHeadersTest.java
@@ -16,6 +16,9 @@
package ee.jakarta.tck.ws.rs.ee.rs.core.headers;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
@@ -68,6 +71,44 @@
}
@GET
+ @Path("/contains-headers")
+ public String containsHeadersGet() {
+ sb = new StringBuffer();
+ sb.append("containsHeaderString= ");
+
+ try {
+ if(hs.containsHeaderString("accept", "text/html"::equals)) {
+ sb.append("Test1: accept contains text/html; ");
+ }
+
+ //Verify Predicate and separator character usage
+ if (hs.containsHeaderString("Accept", ",", "Text/html;Level=1"::equalsIgnoreCase)) {
+ sb.append("Test2: accept contains text/html;level=1; ");
+ }
+
+ //Verify incorrect separator character fails
+ if (!(hs.containsHeaderString("Accept", ";", "text/html;level=1"::equals))) {
+ sb.append("Test3: Incorrect separator character fails as expected; ");
+ }
+
+ //Verify white space in value not trimmed and double character separator
+ if (!(hs.containsHeaderString("header3", ";;", "value3"::equals))) {
+ sb.append("Test4: White space not trimmed from value as expected; ");
+ }
+
+ //Verify white space in front and back of value trimmed
+ if (hs.containsHeaderString("HEADER3", ";;", "value2"::equalsIgnoreCase)) {
+ sb.append("Test5: White space trimmed around value as expected; ");
+ }
+ } catch (Throwable ex) {
+ sb.append("Unexpected exception thrown in containsHeadersGet: "
+ + ex.getMessage());
+ ex.printStackTrace();
+ }
+ return sb.toString();
+ }
+
+ @GET
@Path("/acl")
public String aclGet() {
sb = new StringBuffer();
diff --git a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/JAXRSClientIT.java b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/JAXRSClientIT.java
index 5b3cc4d..bccc459 100644
--- a/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/JAXRSClientIT.java
+++ b/jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/ee/rs/core/headers/JAXRSClientIT.java
@@ -211,6 +211,31 @@
}
/*
+ * @testName: requestHeadersTest
+ *
+ * @assertion_ids: JAXRS:JAVADOC:1361; JAXRS:JAVADOC:1362;
+ *
+ * @test_Strategy: HttpHeaders.containsHeaderString used to confirm that a given header contains
+ * a specified value with the appropriate value separator.
+ */
+ @Test
+ public void containsHeaderStringTest() throws Fault {
+ setProperty(Property.REQUEST_HEADERS,
+ "Accept:text/*, text/html, text/html;level=1, */*");
+ setProperty(Property.REQUEST_HEADERS,
+ "Content-Type:application/xml;charset=utf8");
+ setProperty(Property.REQUEST_HEADERS,
+ "Header3:value1 ;; Value2 ;;value 3");
+ setProperty(Property.REQUEST, buildRequest(Request.GET, "contains-headers"));
+ setProperty(Property.SEARCH_STRING, "Test1");
+ setProperty(Property.SEARCH_STRING, "Test2");
+ setProperty(Property.SEARCH_STRING, "Test3");
+ setProperty(Property.SEARCH_STRING, "Test4");
+ setProperty(Property.SEARCH_STRING, "Test5");
+ invoke();
+ }
+
+ /*
* @testName: getDateTest
*
* @assertion_ids: JAXRS:JAVADOC:779;