vttranlina commented on a change in pull request #711:
URL: https://github.com/apache/james-project/pull/711#discussion_r737061277



##########
File path: 
server/protocols/jmap-rfc-8621/src/test/scala/org/apache/james/jmap/push_subscription/PushServerExtension.scala
##########
@@ -0,0 +1,87 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.push_subscription
+
+import org.junit.jupiter.api.extension.{AfterEachCallback, BeforeEachCallback, 
ExtensionContext, ParameterContext, ParameterResolver}
+import org.mockserver.configuration.ConfigurationProperties
+import org.mockserver.integration.ClientAndServer
+import org.mockserver.integration.ClientAndServer.startClientAndServer
+import org.mockserver.model.HttpRequest.request
+import org.mockserver.model.HttpResponse.response
+import org.mockserver.model.NottableString.{not, string}
+
+import java.time.Clock
+import java.util.UUID
+
+class PushServerExtension extends BeforeEachCallback with AfterEachCallback 
with ParameterResolver {
+  var mockServer: ClientAndServer = _
+
+  override def afterEach(extensionContext: ExtensionContext): Unit = 
mockServer.close()
+
+  override def supportsParameter(parameterContext: ParameterContext, 
extensionContext: ExtensionContext): Boolean =
+    parameterContext.getParameter.getType eq classOf[ClientAndServer]
+
+  override def resolveParameter(parameterContext: ParameterContext, 
extensionContext: ExtensionContext): AnyRef =
+    mockServer
+
+  override def beforeEach(extensionContext: ExtensionContext): Unit = {
+    mockServer = startClientAndServer(0)
+    ConfigurationProperties.logLevel("WARN")
+    MockPushServer.appendSpec(mockServer)
+  }
+
+  def getBaseUrl: String = s"http://127.0.0.1:${mockServer.getLocalPort}";
+}
+
+object MockPushServer {
+  def appendSpec(mockServer: ClientAndServer): Unit = {
+    mockServer
+      .when(request.withHeader(not("TTL")))
+      .respond(response.withStatusCode(400).withBody("missing TTL header"))
+
+    mockServer
+      .when(request.withHeader(not("Content-type")))
+      .respond(response.withStatusCode(400).withBody("Content-type is missing 
or invalid"))
+
+    mockServer
+      .when(request.withHeader(string("Content-type"), not("application/json 
charset=utf-8")))
+      .respond(response.withStatusCode(400).withBody("Content-type is missing 
or invalid"))
+
+    mockServer
+      .when(request.withHeader(not("Urgency")))
+      .respond(response.withStatusCode(400).withBody("Urgency is missing or 
invalid"))
+
+    mockServer
+      .when(request.withHeader(not("Topic")))
+      .respond(response.withStatusCode(400).withBody("Topic is missing or 
invalid"))

Review comment:
       Yes, I thought it was still valid with the push server too, 
   But in James Urgency/Topic is required, So IMO mock-server for James...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to