@@ -21,6 +21,8 @@ package org.apache.james.jmap.pushsubscription
2121
2222import java .net .URL
2323import java .nio .charset .StandardCharsets
24+ import java .time .Clock
25+ import java .util .UUID
2426
2527import org .apache .james .jmap .api .model .PushSubscriptionServerURL
2628import org .apache .james .jmap .pushsubscription .WebPushClientTestFixture .PUSH_REQUEST_SAMPLE
@@ -31,6 +33,7 @@ import org.junit.jupiter.params.provider.ValueSource
3133import org .mockserver .integration .ClientAndServer
3234import org .mockserver .model .HttpRequest .request
3335import org .mockserver .model .HttpResponse .response
36+ import org .mockserver .model .NottableString .string
3437import org .mockserver .verify .VerificationTimes
3538import reactor .core .scala .publisher .SMono
3639
@@ -110,6 +113,36 @@ trait WebPushClientContract {
110113 VerificationTimes .atLeast(1 ))
111114 }
112115
116+ @ ParameterizedTest
117+ @ ValueSource (ints = Array (200 , 201 , 202 ))
118+ def pushClientShouldAcceptFlexible20xCodes (httpStatusCode : Int , pushServer : ClientAndServer ): Unit = {
119+ pushServer
120+ .when(request
121+ .withPath(" /pushh" )
122+ .withMethod(" POST" )
123+ .withHeader(string(" Content-type" ), string(" application/json charset=utf-8" ))
124+ .withHeader(string(" Urgency" ))
125+ .withHeader(string(" Topic" ))
126+ .withHeader(string(" TTL" )))
127+ .respond(response
128+ .withStatusCode(httpStatusCode)
129+ .withHeader(" Location" , String .format(" https://push.example.net/message/%s" , UUID .randomUUID))
130+ .withHeader(" Date" , Clock .systemUTC.toString)
131+ .withBody(UUID .randomUUID.toString))
132+
133+ assertThatCode(() => SMono .fromPublisher(testee.push(PushSubscriptionServerURL .from(s " ${pushServerBaseUrl.toString}/pushh " ).get, PUSH_REQUEST_SAMPLE ))
134+ .block())
135+ .doesNotThrowAnyException()
136+
137+ pushServer.verify(request()
138+ .withPath(" /pushh" )
139+ .withHeader(" TTL" , " 15" )
140+ .withHeader(" Topic" , " topicabc" )
141+ .withHeader(" Urgency" , " High" )
142+ .withBody(new String (PUSH_REQUEST_SAMPLE .payload, StandardCharsets .UTF_8 )),
143+ VerificationTimes .once)
144+ }
145+
113146 @ Test
114147 def pushRequestShouldParserErrorResponseFromPushServerWhenFail (pushServer : ClientAndServer ): Unit = {
115148 pushServer
0 commit comments