This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 8f311bebcac9897b573a01a0fc8b54b9f9609491 Author: James Netherton <[email protected]> AuthorDate: Fri Oct 30 14:26:09 2020 +0000 Stub ServiceNow tests with WireMock --- integration-tests/servicenow/README.adoc | 10 ++++ integration-tests/servicenow/pom.xml | 5 ++ .../servicenow/it/ServicenowResource.java | 2 +- .../component/servicenow/it/model/Incident.java | 2 + .../src/main/resources/application.properties | 23 --------- .../component/servicenow/it/ServicenowIT.java | 4 -- .../component/servicenow/it/ServicenowTest.java | 6 +-- .../servicenow/it/ServicenowTestResource.java | 54 ++++++++++++++++++++++ .../mappings/servicenowConfirmDeleteIncident.json | 29 ++++++++++++ .../mappings/servicenowCreateIncident.json | 33 +++++++++++++ .../mappings/servicenowDeleteIncident.json | 22 +++++++++ .../resources/mappings/servicenowGetIncident.json | 30 ++++++++++++ 12 files changed, 188 insertions(+), 32 deletions(-) diff --git a/integration-tests/servicenow/README.adoc b/integration-tests/servicenow/README.adoc index 528da26..8c2ef6f 100644 --- a/integration-tests/servicenow/README.adoc +++ b/integration-tests/servicenow/README.adoc @@ -1,5 +1,7 @@ == Camel Quarkus ServiceNow Integration Tests +By default the ServiceNow integration tests use WireMock to stub the API interactions. + To run the `camel-quarkus-servicenow` integration tests, you will need a https://servicenow.com[ServiceNow] instance. Then set the following environment variables: @@ -10,3 +12,11 @@ export SERVICENOW_INSTANCE=my-instance export SERVICENOW_USERNAME=my-username export SERVICENOW_PASSWORD=my-password ---- + +If the WireMock stub recordings need updating, then remove the existing files from `src/test/resources/mappings` and run tests with either: + +System property `-Dwiremock.record=true` + +Or + +Set environment variable `WIREMOCK_RECORD=true` diff --git a/integration-tests/servicenow/pom.xml b/integration-tests/servicenow/pom.xml index 95ee843..4fa2f09 100644 --- a/integration-tests/servicenow/pom.xml +++ b/integration-tests/servicenow/pom.xml @@ -54,6 +54,11 @@ <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-wiremock-support</artifactId> + <scope>test</scope> + </dependency> <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> <dependency> diff --git a/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowResource.java b/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowResource.java index d280741..ce2d17c 100644 --- a/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowResource.java +++ b/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowResource.java @@ -49,7 +49,7 @@ public class ServicenowResource { @Inject ProducerTemplate producerTemplate; - @ConfigProperty(name = "servicenow.instance") + @ConfigProperty(name = "camel.component.servicenow.instance-name") String instance; @Path("/post") diff --git a/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/model/Incident.java b/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/model/Incident.java index 91f5f18..9a6b902 100644 --- a/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/model/Incident.java +++ b/integration-tests/servicenow/src/main/java/org/apache/camel/quarkus/component/servicenow/it/model/Incident.java @@ -19,9 +19,11 @@ package org.apache.camel.quarkus.component.servicenow.it.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) +@RegisterForReflection public class Incident { @JsonProperty("sys_id") private String id; diff --git a/integration-tests/servicenow/src/main/resources/application.properties b/integration-tests/servicenow/src/main/resources/application.properties deleted file mode 100644 index 1950833..0000000 --- a/integration-tests/servicenow/src/main/resources/application.properties +++ /dev/null @@ -1,23 +0,0 @@ -## --------------------------------------------------------------------------- -## 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. -## --------------------------------------------------------------------------- - -# -# Camel :: ServiceNow -# -servicenow.instance={{env:SERVICENOW_INSTANCE}} -camel.component.servicenow.username={{env:SERVICENOW_USERNAME}} -camel.component.servicenow.password={{env:SERVICENOW_PASSWORD}} diff --git a/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowIT.java b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowIT.java index 0d0e0c1..6a5acf7 100644 --- a/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowIT.java +++ b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowIT.java @@ -17,12 +17,8 @@ package org.apache.camel.quarkus.component.servicenow.it; import io.quarkus.test.junit.NativeImageTest; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; @NativeImageTest -@EnabledIfEnvironmentVariable(named = "SERVICENOW_INSTANCE", matches = ".+") -@EnabledIfEnvironmentVariable(named = "SERVICENOW_USERNAME", matches = ".+") -@EnabledIfEnvironmentVariable(named = "SERVICENOW_PASSWORD", matches = ".+") class ServicenowIT extends ServicenowTest { } diff --git a/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTest.java b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTest.java index 7b88a56..f328841 100644 --- a/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTest.java +++ b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTest.java @@ -16,18 +16,16 @@ */ package org.apache.camel.quarkus.component.servicenow.it; +import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import static org.hamcrest.Matchers.matchesPattern; @QuarkusTest -@EnabledIfEnvironmentVariable(named = "SERVICENOW_INSTANCE", matches = ".+") -@EnabledIfEnvironmentVariable(named = "SERVICENOW_USERNAME", matches = ".+") -@EnabledIfEnvironmentVariable(named = "SERVICENOW_PASSWORD", matches = ".+") +@QuarkusTestResource(ServicenowTestResource.class) class ServicenowTest { @Test diff --git a/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTestResource.java b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTestResource.java new file mode 100644 index 0000000..c92a4a1 --- /dev/null +++ b/integration-tests/servicenow/src/test/java/org/apache/camel/quarkus/component/servicenow/it/ServicenowTestResource.java @@ -0,0 +1,54 @@ +/* + * 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.quarkus.component.servicenow.it; + +import java.util.Map; + +import org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager; +import org.apache.camel.util.CollectionHelper; + +public class ServicenowTestResource extends WireMockTestResourceLifecycleManager { + + private static final String SERVICENOW_ENV_INSTANCE = "SERVICENOW_INSTANCE"; + private static final String SERVICENOW_ENV_USERNAME = "SERVICENOW_USERNAME"; + private static final String SERVICENOW_ENV_PASSWORD = "SERVICENOW_PASSWORD"; + + @Override + public Map<String, String> start() { + Map<String, String> properties = super.start(); + String wiremockUrl = properties.get("wiremock.url"); + String apiUrl = wiremockUrl != null ? wiremockUrl : getRecordTargetBaseUrl(); + return CollectionHelper.mergeMaps(properties, CollectionHelper.mapOf( + "camel.component.servicenow.instance-name", envOrDefault(SERVICENOW_ENV_INSTANCE, "fake"), + "camel.component.servicenow.username", envOrDefault(SERVICENOW_ENV_USERNAME, "test"), + "camel.component.servicenow.password", envOrDefault(SERVICENOW_ENV_PASSWORD, "2se3r3t"), + "camel.component.servicenow.api-url", apiUrl)); + } + + @Override + protected String getRecordTargetBaseUrl() { + return String.format("https://%s.service-now.com/api", System.getenv(SERVICENOW_ENV_INSTANCE)); + } + + @Override + protected boolean isMockingEnabled() { + return !envVarsPresent( + SERVICENOW_ENV_INSTANCE, + SERVICENOW_ENV_USERNAME, + SERVICENOW_ENV_PASSWORD); + } +} diff --git a/integration-tests/servicenow/src/test/resources/mappings/servicenowConfirmDeleteIncident.json b/integration-tests/servicenow/src/test/resources/mappings/servicenowConfirmDeleteIncident.json new file mode 100644 index 0000000..4149714 --- /dev/null +++ b/integration-tests/servicenow/src/test/resources/mappings/servicenowConfirmDeleteIncident.json @@ -0,0 +1,29 @@ +{ + "id" : "a5b46fb7-d51e-49f5-84d2-5f22a4eadeb3", + "name" : "now_v1_table_incident_9aae36efdb4020505b022ad94b9619cc", + "request" : { + "url" : "/now/v1/table/incident/9aae36efdb4020505b022ad94b9619cc?sysparm_display_value=false&sysparm_exclude_reference_link=false", + "method" : "GET" + }, + "response" : { + "status" : 404, + "body" : "{\"error\":{\"message\":\"No Record found\",\"detail\":\"Record doesn't exist or ACL restricts the record retrieval\"},\"status\":\"failure\"}", + "headers" : { + "X-Is-Logged-In" : "true", + "X-Transaction-ID" : "faaeba2f1bc4", + "Pragma" : "no-store,no-cache", + "Cache-control" : "no-cache,no-store,must-revalidate,max-age=-1", + "Expires" : "0", + "Content-Type" : "application/json;charset=UTF-8", + "Date" : "Fri, 30 Oct 2020 14:12:31 GMT", + "Server" : "ServiceNow", + "Set-Cookie" : [ "JSESSIONID=4BF3C6F757D76F05F9B24C9F04E22358; Path=/; HttpOnly; SameSite=None; Secure", "glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_route=glide.47b57eb1ea96b0d680a38a6721421254; Max-Age=2147483647; Expires=Wed, 17-Nov-2088 17:26:39 GMT; Path=/; HttpOnly; SameSite=None; Secure", "g [...] + "Strict-Transport-Security" : "max-age=63072000; includeSubDomains" + } + }, + "uuid" : "a5b46fb7-d51e-49f5-84d2-5f22a4eadeb3", + "persistent" : true, + "scenarioName" : "scenario-1-now-v1-table-incident-9aae36efdb4020505b022ad94b9619cc", + "requiredScenarioState" : "scenario-1-now-v1-table-incident-9aae36efdb4020505b022ad94b9619cc-2", + "insertionIndex" : 4 +} \ No newline at end of file diff --git a/integration-tests/servicenow/src/test/resources/mappings/servicenowCreateIncident.json b/integration-tests/servicenow/src/test/resources/mappings/servicenowCreateIncident.json new file mode 100644 index 0000000..e5a966c --- /dev/null +++ b/integration-tests/servicenow/src/test/resources/mappings/servicenowCreateIncident.json @@ -0,0 +1,33 @@ +{ + "id" : "eff347f9-40ff-40b8-aa22-3fd1f10548bb", + "name" : "now_v1_table_incident", + "request" : { + "url" : "/now/v1/table/incident?sysparm_display_value=false&sysparm_exclude_reference_link=false&sysparm_input_display_value=false&sysparm_suppress_auto_sys_field=false", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"description\":\"Demo incident\",\"severity\":1,\"impact\":1}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 201, + "body" : "{\"result\":{\"parent\":\"\",\"made_sla\":\"true\",\"caused_by\":\"\",\"watch_list\":\"\",\"upon_reject\":\"cancel\",\"sys_updated_on\":\"2020-10-30 14:12:31\",\"child_incidents\":\"0\",\"approval_history\":\"\",\"skills\":\"\",\"number\":\"INC0011411\",\"resolved_by\":\"\",\"sys_updated_by\":\"admin\",\"opened_by\":{\"link\":\"https://fake.service-now.com/api/now/v1/table/sys_user/6816f79cc0a8016401c5a33be04be441\",\"value\":\"6816f79cc0a8016401c5a33be04be441\"},\"user_inp [...] + "headers" : { + "X-Is-Logged-In" : "true", + "X-Transaction-ID" : "deae726fdbcc", + "Location" : "https://fake.service-now.com/api/now/v1/table/incident/9aae36efdb4020505b022ad94b9619cc", + "Pragma" : "no-store,no-cache", + "Cache-control" : "no-cache,no-store,must-revalidate,max-age=-1", + "Expires" : "0", + "Content-Type" : "application/json;charset=UTF-8", + "Date" : "Fri, 30 Oct 2020 14:12:31 GMT", + "Server" : "ServiceNow", + "Set-Cookie" : [ "JSESSIONID=97FE019CBE537FADAA5D3BBC643BB0EB; Path=/; HttpOnly; SameSite=None; Secure", "glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_route=glide.1b928f91f1244fdcdc488a67644bfe83; Max-Age=2147483647; Expires=Wed, 17-Nov-2088 17:26:38 GMT; Path=/; HttpOnly; SameSite=None; Secure", "g [...] + "Strict-Transport-Security" : "max-age=63072000; includeSubDomains" + } + }, + "uuid" : "eff347f9-40ff-40b8-aa22-3fd1f10548bb", + "persistent" : true, + "insertionIndex" : 1 +} \ No newline at end of file diff --git a/integration-tests/servicenow/src/test/resources/mappings/servicenowDeleteIncident.json b/integration-tests/servicenow/src/test/resources/mappings/servicenowDeleteIncident.json new file mode 100644 index 0000000..0119c98 --- /dev/null +++ b/integration-tests/servicenow/src/test/resources/mappings/servicenowDeleteIncident.json @@ -0,0 +1,22 @@ +{ + "id" : "96dff3b5-f262-449e-9898-afae52a7e035", + "name" : "now_v1_table_incident_9aae36efdb4020505b022ad94b9619cc", + "request" : { + "url" : "/now/v1/table/incident/9aae36efdb4020505b022ad94b9619cc", + "method" : "DELETE" + }, + "response" : { + "status" : 204, + "headers" : { + "X-Is-Logged-In" : "true", + "X-Transaction-ID" : "a2ae36efdb40", + "Date" : "Fri, 30 Oct 2020 14:12:32 GMT", + "Server" : "ServiceNow", + "Set-Cookie" : [ "JSESSIONID=90305EB445391DB5306650D650364F5F; Path=/; HttpOnly; SameSite=None; Secure", "glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_route=glide.1b928f91f1244fdcdc488a67644bfe83; Max-Age=2147483647; Expires=Wed, 17-Nov-2088 17:26:39 GMT; Path=/; HttpOnly; SameSite=None; Secure", "g [...] + "Strict-Transport-Security" : "max-age=63072000; includeSubDomains" + } + }, + "uuid" : "96dff3b5-f262-449e-9898-afae52a7e035", + "persistent" : true, + "insertionIndex" : 3 +} \ No newline at end of file diff --git a/integration-tests/servicenow/src/test/resources/mappings/servicenowGetIncident.json b/integration-tests/servicenow/src/test/resources/mappings/servicenowGetIncident.json new file mode 100644 index 0000000..bdcbf05 --- /dev/null +++ b/integration-tests/servicenow/src/test/resources/mappings/servicenowGetIncident.json @@ -0,0 +1,30 @@ +{ + "id" : "a167cd27-014f-4b33-8251-e142206925e0", + "name" : "now_v1_table_incident_9aae36efdb4020505b022ad94b9619cc", + "request" : { + "url" : "/now/v1/table/incident/9aae36efdb4020505b022ad94b9619cc?sysparm_display_value=false&sysparm_exclude_reference_link=false", + "method" : "GET" + }, + "response" : { + "status" : 200, + "body" : "{\"result\":{\"parent\":\"\",\"made_sla\":\"true\",\"caused_by\":\"\",\"watch_list\":\"\",\"upon_reject\":\"cancel\",\"sys_updated_on\":\"2020-10-30 14:12:31\",\"child_incidents\":\"0\",\"approval_history\":\"\",\"skills\":\"\",\"number\":\"INC0011411\",\"resolved_by\":\"\",\"sys_updated_by\":\"admin\",\"opened_by\":{\"link\":\"https://fake.service-now.com/api/now/v1/table/sys_user/6816f79cc0a8016401c5a33be04be441\",\"value\":\"6816f79cc0a8016401c5a33be04be441\"},\"user_inp [...] + "headers" : { + "X-Is-Logged-In" : "true", + "X-Transaction-ID" : "e2ae36eb1bc4", + "Pragma" : "no-store,no-cache", + "Cache-control" : "no-cache,no-store,must-revalidate,max-age=-1", + "Expires" : "0", + "Content-Type" : "application/json;charset=UTF-8", + "Date" : "Fri, 30 Oct 2020 14:12:31 GMT", + "Server" : "ServiceNow", + "Set-Cookie" : [ "JSESSIONID=41F549D2595A94AE9FE0B8FAFB1509E9; Path=/; HttpOnly; SameSite=None; Secure", "glide_user=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_session=; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly; SameSite=None; Secure", "glide_user_route=glide.47b57eb1ea96b0d680a38a6721421254; Max-Age=2147483647; Expires=Wed, 17-Nov-2088 17:26:38 GMT; Path=/; HttpOnly; SameSite=None; Secure", "g [...] + "Strict-Transport-Security" : "max-age=63072000; includeSubDomains" + } + }, + "uuid" : "a167cd27-014f-4b33-8251-e142206925e0", + "persistent" : true, + "scenarioName" : "scenario-1-now-v1-table-incident-9aae36efdb4020505b022ad94b9619cc", + "requiredScenarioState" : "Started", + "newScenarioState" : "scenario-1-now-v1-table-incident-9aae36efdb4020505b022ad94b9619cc-2", + "insertionIndex" : 2 +} \ No newline at end of file
