Skip to content

Commit

Permalink
Use WireMock for GitHub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed May 20, 2021
1 parent ba887e6 commit ca40252
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 0 deletions.
20 changes: 20 additions & 0 deletions integration-tests/github/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
== Camel Quarkus GitHub Integration Tests

By default the GitHub integration tests use WireMock to stub the API interactions.

To run the `camel-quarkus-github` integration tests against the real API, you must first create a https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token[GitHub token].

Set the following environment variable:

[source,shell]
----
export GITHUB_TOKEN=your-token
----

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`
5 changes: 5 additions & 0 deletions integration-tests/github/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-wiremock-support</artifactId>
<scope>test</scope>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
*/
package org.apache.camel.quarkus.component.github.it;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;

import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.github.GitHubConstants;
import org.apache.camel.impl.event.CamelContextStartedEvent;
import org.eclipse.egit.github.core.CommitFile;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.DataService;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

@Path("/github")
public class GithubResource {
Expand All @@ -33,6 +46,31 @@ public class GithubResource {
@Inject
ProducerTemplate producerTemplate;

public void onContextStart(@Observes CamelContextStartedEvent event) {
Config config = ConfigProvider.getConfig();
Optional<String> wireMockUrl = config.getOptionalValue("wiremock.url", String.class);
if (wireMockUrl.isPresent()) {
// Force the GH client to use the WireMock proxy
try {
CamelContext context = event.getContext();
URI wireMockUri = new URI(wireMockUrl.get());
GitHubClient client = new GitHubClient(wireMockUri.getHost(), wireMockUri.getPort(), wireMockUri.getScheme()) {
@Override
protected String configureUri(String uri) {
// Prevent the original impl adding an unwanted /v3 path prefix
return uri;
}
};
DataService dataService = new DataService(client);
RepositoryService repositoryService = new RepositoryService(client);
context.getRegistry().bind(GitHubConstants.GITHUB_DATA_SERVICE, dataService);
context.getRegistry().bind(GitHubConstants.GITHUB_REPOSITORY_SERVICE, repositoryService);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}

@Path("/get")
@GET
@Produces(MediaType.TEXT_PLAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
*/
package org.apache.camel.quarkus.component.github.it;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.containsString;

@QuarkusTest
@QuarkusTestResource(GithubTestResource.class)
class GithubTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.github.it;

import org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager;

public class GithubTestResource extends WireMockTestResourceLifecycleManager {

private static final String GITHUB_ENV_TOKEN = "GITHUB_TOKEN";

@Override
protected String getRecordTargetBaseUrl() {
return "https://api.github.com";
}

@Override
protected boolean isMockingEnabled() {
return !envVarsPresent(GITHUB_ENV_TOKEN);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id" : "85e3cc39-9d71-45a1-863c-7989052af075",
"name" : "repos_apache_camel-quarkus",
"request" : {
"url" : "/repos/apache/camel-quarkus",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"id\":193065376,\"node_id\":\"MDEwOlJlcG9zaXRvcnkxOTMwNjUzNzY=\",\"name\":\"camel-quarkus\",\"full_name\":\"apache/camel-quarkus\",\"private\":false,\"owner\":{\"login\":\"apache\",\"id\":47359,\"node_id\":\"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/47359?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/apache\",\"html_url\":\"https://github.com/apache\",\"followers_url\":\"https://api.github.com/users/apache/followers\",\"following_url\":\"https://api.github.com/users/apache/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/apache/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/apache/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/apache/subscriptions\",\"organizations_url\":\"https://api.github.com/users/apache/orgs\",\"repos_url\":\"https://api.github.com/users/apache/repos\",\"events_url\":\"https://api.github.com/users/apache/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/apache/received_events\",\"type\":\"Organization\",\"site_admin\":false},\"html_url\":\"https://github.com/apache/camel-quarkus\",\"description\":\"Apache Camel Quarkus support\",\"fork\":false,\"url\":\"https://api.github.com/repos/apache/camel-quarkus\",\"forks_url\":\"https://api.github.com/repos/apache/camel-quarkus/forks\",\"keys_url\":\"https://api.github.com/repos/apache/camel-quarkus/keys{/key_id}\",\"collaborators_url\":\"https://api.github.com/repos/apache/camel-quarkus/collaborators{/collaborator}\",\"teams_url\":\"https://api.github.com/repos/apache/camel-quarkus/teams\",\"hooks_url\":\"https://api.github.com/repos/apache/camel-quarkus/hooks\",\"issue_events_url\":\"https://api.github.com/repos/apache/camel-quarkus/issues/events{/number}\",\"events_url\":\"https://api.github.com/repos/apache/camel-quarkus/events\",\"assignees_url\":\"https://api.github.com/repos/apache/camel-quarkus/assignees{/user}\",\"branches_url\":\"https://api.github.com/repos/apache/camel-quarkus/branches{/branch}\",\"tags_url\":\"https://api.github.com/repos/apache/camel-quarkus/tags\",\"blobs_url\":\"https://api.github.com/repos/apache/camel-quarkus/git/blobs{/sha}\",\"git_tags_url\":\"https://api.github.com/repos/apache/camel-quarkus/git/tags{/sha}\",\"git_refs_url\":\"https://api.github.com/repos/apache/camel-quarkus/git/refs{/sha}\",\"trees_url\":\"https://api.github.com/repos/apache/camel-quarkus/git/trees{/sha}\",\"statuses_url\":\"https://api.github.com/repos/apache/camel-quarkus/statuses/{sha}\",\"languages_url\":\"https://api.github.com/repos/apache/camel-quarkus/languages\",\"stargazers_url\":\"https://api.github.com/repos/apache/camel-quarkus/stargazers\",\"contributors_url\":\"https://api.github.com/repos/apache/camel-quarkus/contributors\",\"subscribers_url\":\"https://api.github.com/repos/apache/camel-quarkus/subscribers\",\"subscription_url\":\"https://api.github.com/repos/apache/camel-quarkus/subscription\",\"commits_url\":\"https://api.github.com/repos/apache/camel-quarkus/commits{/sha}\",\"git_commits_url\":\"https://api.github.com/repos/apache/camel-quarkus/git/commits{/sha}\",\"comments_url\":\"https://api.github.com/repos/apache/camel-quarkus/comments{/number}\",\"issue_comment_url\":\"https://api.github.com/repos/apache/camel-quarkus/issues/comments{/number}\",\"contents_url\":\"https://api.github.com/repos/apache/camel-quarkus/contents/{+path}\",\"compare_url\":\"https://api.github.com/repos/apache/camel-quarkus/compare/{base}...{head}\",\"merges_url\":\"https://api.github.com/repos/apache/camel-quarkus/merges\",\"archive_url\":\"https://api.github.com/repos/apache/camel-quarkus/{archive_format}{/ref}\",\"downloads_url\":\"https://api.github.com/repos/apache/camel-quarkus/downloads\",\"issues_url\":\"https://api.github.com/repos/apache/camel-quarkus/issues{/number}\",\"pulls_url\":\"https://api.github.com/repos/apache/camel-quarkus/pulls{/number}\",\"milestones_url\":\"https://api.github.com/repos/apache/camel-quarkus/milestones{/number}\",\"notifications_url\":\"https://api.github.com/repos/apache/camel-quarkus/notifications{?since,all,participating}\",\"labels_url\":\"https://api.github.com/repos/apache/camel-quarkus/labels{/name}\",\"releases_url\":\"https://api.github.com/repos/apache/camel-quarkus/releases{/id}\",\"deployments_url\":\"https://api.github.com/repos/apache/camel-quarkus/deployments\",\"created_at\":\"2019-06-21T08:55:25Z\",\"updated_at\":\"2021-05-20T03:40:17Z\",\"pushed_at\":\"2021-05-20T07:17:36Z\",\"git_url\":\"git://github.com/apache/camel-quarkus.git\",\"ssh_url\":\"git@github.com:apache/camel-quarkus.git\",\"clone_url\":\"https://github.com/apache/camel-quarkus.git\",\"svn_url\":\"https://github.com/apache/camel-quarkus\",\"homepage\":\"https://camel.apache.org\",\"size\":20828,\"stargazers_count\":116,\"watchers_count\":116,\"language\":\"Java\",\"has_issues\":true,\"has_projects\":true,\"has_downloads\":true,\"has_wiki\":false,\"has_pages\":false,\"forks_count\":99,\"mirror_url\":null,\"archived\":false,\"disabled\":false,\"open_issues_count\":262,\"license\":{\"key\":\"apache-2.0\",\"name\":\"Apache License 2.0\",\"spdx_id\":\"Apache-2.0\",\"url\":\"https://api.github.com/licenses/apache-2.0\",\"node_id\":\"MDc6TGljZW5zZTI=\"},\"forks\":99,\"open_issues\":262,\"watchers\":116,\"default_branch\":\"main\",\"master_branch\":\"main\",\"temp_clone_token\":null,\"organization\":{\"login\":\"apache\",\"id\":47359,\"node_id\":\"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/47359?v=4\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/apache\",\"html_url\":\"https://github.com/apache\",\"followers_url\":\"https://api.github.com/users/apache/followers\",\"following_url\":\"https://api.github.com/users/apache/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/apache/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/apache/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/apache/subscriptions\",\"organizations_url\":\"https://api.github.com/users/apache/orgs\",\"repos_url\":\"https://api.github.com/users/apache/repos\",\"events_url\":\"https://api.github.com/users/apache/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/apache/received_events\",\"type\":\"Organization\",\"site_admin\":false},\"network_count\":99,\"subscribers_count\":27}",
"headers" : {
"Server" : "GitHub.com",
"Date" : "Thu, 20 May 2021 10:38:18 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Cache-Control" : "public, max-age=60, s-maxage=60",
"Vary" : "Accept, Accept-Encoding, Accept, X-Requested-With",
"ETag" : "W/\"7a87e6c15f634559e9085861786f1e47ae9949c046cd43a5f12af7b3cf813183\"",
"Last-Modified" : "Thu, 20 May 2021 03:40:17 GMT",
"X-GitHub-Media-Type" : "github.beta; format=json",
"Strict-Transport-Security" : "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options" : "deny",
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "0",
"Referrer-Policy" : "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy" : "default-src 'none'",
"X-RateLimit-Limit" : "60",
"X-RateLimit-Remaining" : "58",
"X-RateLimit-Reset" : "1621510517",
"X-RateLimit-Resource" : "core",
"X-RateLimit-Used" : "2",
"Accept-Ranges" : "bytes",
"X-GitHub-Request-Id" : "A086:97B8:1BF790:1E9A3C:60A63C19"
}
},
"uuid" : "85e3cc39-9d71-45a1-863c-7989052af075",
"persistent" : true,
"insertionIndex" : 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"id" : "b61eef33-a160-48e7-95e1-40349b7f5e1e",
"name" : "repos_apache_camel-quarkus_git_blobs_6195efafd0a8100795247e35942b5c61fea79267",
"request" : {
"url" : "/repos/apache/camel-quarkus/git/blobs/6195efafd0a8100795247e35942b5c61fea79267",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"sha\":\"6195efafd0a8100795247e35942b5c61fea79267\",\"node_id\":\"MDQ6QmxvYjE5MzA2NTM3Njo2MTk1ZWZhZmQwYTgxMDA3OTUyNDdlMzU5NDJiNWM2MWZlYTc5MjY3\",\"size\":1614,\"url\":\"https://api.github.com/repos/apache/camel-quarkus/git/blobs/6195efafd0a8100795247e35942b5c61fea79267\",\"content\":\"PSBBcGFjaGUgQ2FtZWwgZXh0ZW5zaW9ucyBmb3IgUXVhcmt1cwoKaW1hZ2U6\\naHR0cHM6Ly9pbWcuc2hpZWxkcy5pby9tYXZlbi1jZW50cmFsL3Yvb3JnLmFw\\nYWNoZS5jYW1lbC5xdWFya3VzL2NhbWVsLXF1YXJrdXMtYm9tLnN2Z1siTWF2\\nZW4gQ2VudHJhbCIsIGxpbms9Imh0dHA6Ly9zZWFyY2gubWF2ZW4ub3JnLyNz\\nZWFyY2glN0NnYSU3QzElN0NvcmcuYXBhY2hlLmNhbWVsLnF1YXJrdXMiXQpp\\nbWFnZTpodHRwczovL2ltZy5zaGllbGRzLmlvL2dpdGh1Yi9saWNlbnNlL29w\\nZW5zaGlmdC9vcmlnaW4uc3ZnP21heEFnZT0yNTkyMDAwWyJMaWNlbnNlZCB1\\nbmRlciBBcGFjaGUgTGljZW5zZSB2ZXJzaW9uIDIuMCIsIGxpbms9Imh0dHBz\\nOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAiXQppbWFn\\nZTpodHRwczovL2JhZGdlcy5naXR0ZXIuaW0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hcmt1cyBhcHBsaWNhdGlvbi4gWW91\\nIHdpbGwgdHlwaWNhbGx5IHVzZSB0aGVtIGFzIGRlcGVuZGVuY2llcwppbiB5\\nb3VyIHByb2plY3QuCgoKPT0gSG93IHRvIGJ1aWxkCgpTZWUgdGhlIGNvbnRy\\naWJ1dG9yIGd1aWRlIHhyZWY6ZG9jcy9tb2R1bGVzL1JPT1QvcGFnZXMvY29u\\ndHJpYnV0b3ItZ3VpZGUuYWRvY1tpbiB0aGUgc291cmNlIHRyZWVdIG9yIG9u\\nIHRoZQpodHRwczovL2NhbWVsLmFwYWNoZS5vcmcvY2FtZWwtcXVhcmt1cy9s\\nYXRlc3QvY29udHJpYnV0b3ItZ3VpZGUuaHRtbFtBcGFjaGUgQ2FtZWwgd2Vi\\nc2l0ZV0uCgoKPT0gTGljZW5zaW5nCgpUaGlzIHNvZnR3YXJlIGlzIGxpY2Vu\\nc2VkIHVuZGVyIHRoZSB0ZXJtcyB5b3UgbWF5IGZpbmQgaW4gdGhlIGZpbGUg\\nbmFtZWQgYExJQ0VOU0UudHh0YCBpbiB0aGlzIGRpcmVjdG9yeS4K\\n\",\"encoding\":\"base64\"}",
"headers" : {
"Server" : "GitHub.com",
"Date" : "Thu, 20 May 2021 10:38:31 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Cache-Control" : "public, max-age=60, s-maxage=60",
"Vary" : "Accept, Accept-Encoding, Accept, X-Requested-With",
"ETag" : "W/\"f7af62dc21539a2acbc6159b8869ab60dccd4da5e92eeead36caddd9281d0ae3\"",
"X-GitHub-Media-Type" : "github.beta; format=json",
"Strict-Transport-Security" : "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options" : "deny",
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "0",
"Referrer-Policy" : "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy" : "default-src 'none'",
"X-RateLimit-Limit" : "60",
"X-RateLimit-Remaining" : "57",
"X-RateLimit-Reset" : "1621510517",
"X-RateLimit-Resource" : "core",
"X-RateLimit-Used" : "3",
"Accept-Ranges" : "bytes",
"X-GitHub-Request-Id" : "A086:97B8:1BFAA5:1E9D8A:60A63C27"
}
},
"uuid" : "b61eef33-a160-48e7-95e1-40349b7f5e1e",
"persistent" : true,
"insertionIndex" : 2
}

0 comments on commit ca40252

Please sign in to comment.