You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/03/11 12:47:47 UTC
[GitHub] [camel-kafka-connector] tadayosi opened a new pull request #1097: Introduce MockWebServer extension for testing #1085
tadayosi opened a new pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097
- Add MockWebService JUnit 5 extension for general usages in testing HTTP sinks.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592349021
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
Review comment:
Thanks for the explanation. One reason I'd like to avoid adding more dependencies in itest common is to reduce the risk of conflict with the Kafka Connect runtime. It has been quite common for our tests to have problems caused by conflicts with jetty, netty and a few other libraries uses by the Kafka Connect runtime (HDFS is a notorious example of a problematic component for this).
We could create a itests-http-common component and put this code there. As such it would be isolated and used only for the ones that need it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592353943
##########
File path: tests/itests-common/pom.xml
##########
@@ -28,6 +28,14 @@
<artifactId>itests-common</artifactId>
<name>Camel-Kafka-Connector :: Tests :: Common</name>
+ <dependencies>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>mockwebserver</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
Review comment:
It's related to my comment below, about reducing the risk of conflicts w/ Kafka's Connect own runtime. We should have it in a separate test component.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] tadayosi commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
tadayosi commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592351952
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
Review comment:
Got it. I'll work on it later.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] tadayosi commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
tadayosi commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592345678
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
+ private static final Logger LOG = LoggerFactory.getLogger(MockWebService.class);
+
+ private boolean useHttps;
+ private String keystore;
+ private String keystorePassword;
+ private String truststore;
+ private String truststorePassword;
+
+ private MockWebServer server;
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) throws Exception {
+ LOG.debug("Starting MockWebServer...");
+ server = new MockWebServer();
+ if (useHttps) {
+ KeyManagerFactory kmFactory = null;
+ if (keystore != null) {
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ String password = keystorePassword == null ? "" : keystorePassword;
+ keyStore.load(getClass().getResourceAsStream(keystore), password.toCharArray());
+ kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmFactory.init(keyStore, password.toCharArray());
+ }
+ TrustManagerFactory tmFactory = null;
+ if (truststore != null) {
+ KeyStore trustStore = KeyStore.getInstance("JKS");
+ String password = truststorePassword == null ? "" : truststorePassword;
+ trustStore.load(getClass().getResourceAsStream(truststore), password.toCharArray());
+ tmFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ tmFactory.init(trustStore);
+ }
+ SSLContext sslContext = SSLContext.getInstance("TLS");
Review comment:
Not sure about other connectors' itests but for now this should be sufficient for one-way and two-way ssl usages. I think we can gradually evolve the API when we find more use cases.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] tadayosi commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
tadayosi commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592343564
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
Review comment:
The extension is used (at least for now) from two itests, itests-https and itests-netty-http, so I thought itests-common is the place for the extension.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] tadayosi commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
tadayosi commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592342089
##########
File path: tests/itests-common/pom.xml
##########
@@ -28,6 +28,14 @@
<artifactId>itests-common</artifactId>
<name>Camel-Kafka-Connector :: Tests :: Common</name>
+ <dependencies>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>mockwebserver</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
Review comment:
But the dependency is needed for implementing the MockWebService. Am I missing anything?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592336078
##########
File path: tests/itests-common/pom.xml
##########
@@ -28,6 +28,14 @@
<artifactId>itests-common</artifactId>
<name>Camel-Kafka-Connector :: Tests :: Common</name>
+ <dependencies>
+ <dependency>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>mockwebserver</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
Review comment:
I think this should be in the http itests.
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
+ private static final Logger LOG = LoggerFactory.getLogger(MockWebService.class);
+
+ private boolean useHttps;
+ private String keystore;
+ private String keystorePassword;
+ private String truststore;
+ private String truststorePassword;
+
+ private MockWebServer server;
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) throws Exception {
+ LOG.debug("Starting MockWebServer...");
+ server = new MockWebServer();
+ if (useHttps) {
+ KeyManagerFactory kmFactory = null;
+ if (keystore != null) {
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ String password = keystorePassword == null ? "" : keystorePassword;
+ keyStore.load(getClass().getResourceAsStream(keystore), password.toCharArray());
+ kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmFactory.init(keyStore, password.toCharArray());
+ }
+ TrustManagerFactory tmFactory = null;
+ if (truststore != null) {
+ KeyStore trustStore = KeyStore.getInstance("JKS");
+ String password = truststorePassword == null ? "" : truststorePassword;
+ trustStore.load(getClass().getResourceAsStream(truststore), password.toCharArray());
+ tmFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ tmFactory.init(trustStore);
+ }
+ SSLContext sslContext = SSLContext.getInstance("TLS");
Review comment:
Is this something that changes often and could be reuse for other tests? Maybe we should make this whole part (lines 51 to 68) a bit more configurable.
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
Review comment:
I think this one should be either in itests-http or in a new module in camel-test-infra in camel master.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592349021
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
Review comment:
Thanks for the explanation. One reason I'd like to avoid adding more dependencies in itest common is to reduce the risk of conflict with the Kafka Connect runtime. It has been quite common for our tests to have problems caused by conflicts with jetty, netty and a few other libraries used by the Kafka Connect runtime (HDFS is a notorious example of a problematic component for this).
We could create a itests-http-common component and put this code there. As such it would be isolated and used only for the ones that need it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske merged pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske merged pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] tadayosi commented on pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
tadayosi commented on pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#issuecomment-797261210
@orpiske Created new itests-common-http and moved the extension & deps into that project.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-kafka-connector] orpiske commented on a change in pull request #1097: Introduce MockWebServer extension for testing #1085
Posted by GitBox <gi...@apache.org>.
orpiske commented on a change in pull request #1097:
URL: https://github.com/apache/camel-kafka-connector/pull/1097#discussion_r592351082
##########
File path: tests/itests-common/src/test/java/org/apache/camel/kafkaconnector/common/services/mockweb/MockWebService.java
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.camel.kafkaconnector.common.services.mockweb;
+
+import java.security.KeyStore;
+import java.util.stream.IntStream;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockWebService implements BeforeEachCallback, AfterEachCallback {
+ private static final Logger LOG = LoggerFactory.getLogger(MockWebService.class);
+
+ private boolean useHttps;
+ private String keystore;
+ private String keystorePassword;
+ private String truststore;
+ private String truststorePassword;
+
+ private MockWebServer server;
+
+ @Override
+ public void beforeEach(ExtensionContext extensionContext) throws Exception {
+ LOG.debug("Starting MockWebServer...");
+ server = new MockWebServer();
+ if (useHttps) {
+ KeyManagerFactory kmFactory = null;
+ if (keystore != null) {
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ String password = keystorePassword == null ? "" : keystorePassword;
+ keyStore.load(getClass().getResourceAsStream(keystore), password.toCharArray());
+ kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmFactory.init(keyStore, password.toCharArray());
+ }
+ TrustManagerFactory tmFactory = null;
+ if (truststore != null) {
+ KeyStore trustStore = KeyStore.getInstance("JKS");
+ String password = truststorePassword == null ? "" : truststorePassword;
+ trustStore.load(getClass().getResourceAsStream(truststore), password.toCharArray());
+ tmFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ tmFactory.init(trustStore);
+ }
+ SSLContext sslContext = SSLContext.getInstance("TLS");
Review comment:
Ahh, in this case I think it looks fine. We can improve it with time.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org