-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test kamelet-chucknorris project with WireMock
- Loading branch information
1 parent
6361e22
commit f4d37cf
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
kamelet-chucknorris/src/test/java/org/acme/kamelet/ChuckNorrisTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.acme.kamelet; | ||
|
||
import java.util.Map; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
import org.jboss.logging.Logger; | ||
|
||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
|
||
public class ChuckNorrisTestResource implements QuarkusTestResourceLifecycleManager { | ||
private static final Logger LOG = Logger.getLogger(ChuckNorrisTestResource.class); | ||
private static final String WIREMOCK_RECORD = System.getProperty("wiremock.record"); | ||
private WireMockServer wireMock; | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
LOG.info("Starting WireMock"); | ||
|
||
wireMock = new WireMockServer(wireMockConfig().dynamicPort()); | ||
if (WIREMOCK_RECORD != null && WIREMOCK_RECORD.equals("true")) { | ||
LOG.info("Enable WireMock record mode"); | ||
wireMock.resetMappings(); | ||
wireMock.startRecording("https://api.chucknorris.io/jokes/random"); | ||
} | ||
|
||
wireMock.start(); | ||
|
||
String endpointUri = "http://localhost:%d".formatted(wireMock.port()); | ||
LOG.infof("Started WireMock on %s", endpointUri); | ||
|
||
return Map.of( | ||
"chuck.norris.api.url", endpointUri, | ||
"camel.main.globalOptions[http.proxyHost]", "localhost", | ||
"camel.main.globalOptions[http.proxyPort]", String.valueOf(wireMock.port()), | ||
"camel.main.globalOptions[https.proxyHost]", "localhost", | ||
"camel.main.globalOptions[https.proxyPort]", String.valueOf(wireMock.port())); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (wireMock != null) { | ||
if (WIREMOCK_RECORD != null && WIREMOCK_RECORD.equals("true")) { | ||
wireMock.stopRecording(); | ||
wireMock.saveMappings(); | ||
} | ||
wireMock.stop(); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
kamelet-chucknorris/src/test/resources/mappings/chuck-norris-joke.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"id" : "abdc7f6a-5112-44ff-97ac-a0710e342d03", | ||
"name" : "", | ||
"request" : { | ||
"url" : "/", | ||
"method" : "GET" | ||
}, | ||
"response" : { | ||
"status" : 200, | ||
"body" : "{\"categories\":[\"dev\"],\"created_at\":\"2020-01-05 13:42:19.104863\",\"icon_url\":\"https://api.chucknorris.io/img/avatar/chuck-norris.png\",\"id\":\"ye0_hnd3rgq68e_pfvsqqg\",\"updated_at\":\"2020-01-05 13:42:19.104863\",\"url\":\"https://api.chucknorris.io/jokes/ye0_hnd3rgq68e_pfvsqqg\",\"value\":\"Chuck Norris can instantiate an abstract class.\"}", | ||
"headers" : { | ||
"CF-RAY" : "8c205cf67a8f6545-LHR", | ||
"Server" : "cloudflare", | ||
"cf-cache-status" : "DYNAMIC", | ||
"Reporting-Endpoints" : "heroku-nel=https://nel.heroku.com/reports?ts=1726148990&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=DWG%2F2oGJJCxAbiAESBX%2BG7xgCh%2B01nvzoILE2LS0jo4%3D", | ||
"Date" : "Thu, 12 Sep 2024 13:49:50 GMT", | ||
"Via" : "1.1 vegur", | ||
"Nel" : "{\"report_to\":\"heroku-nel\",\"max_age\":3600,\"success_fraction\":0.005,\"failure_fraction\":0.05,\"response_headers\":[\"Via\"]}", | ||
"Report-To" : "{\"group\":\"heroku-nel\",\"max_age\":3600,\"endpoints\":[{\"url\":\"https://nel.heroku.com/reports?ts=1726148990&sid=812dcc77-0bd0-43b1-a5f1-b25750382959&s=DWG%2F2oGJJCxAbiAESBX%2BG7xgCh%2B01nvzoILE2LS0jo4%3D\"}]}", | ||
"Vary" : [ "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers" ], | ||
"alt-svc" : "h3=\":443\"; ma=86400", | ||
"Content-Type" : "application/json" | ||
} | ||
}, | ||
"uuid" : "abdc7f6a-5112-44ff-97ac-a0710e342d03", | ||
"persistent" : true, | ||
"insertionIndex" : 1 | ||
} |