Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce java 11 due to openapi generator compatibility #74

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.distsDirectory

group = "com.gradle.enterprise.api"
description = "Gradle Enterprise API sample"

Expand Down Expand Up @@ -32,18 +34,25 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2")
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("org.apache.httpcomponents.client5:httpclient5:5.2.1")

testImplementation("org.mock-server:mockserver-netty:5.15.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

}

val gradleEnterpriseVersion = "2023.2" // Must be later than 2022.1
val baseApiUrl = providers.gradleProperty("apiManualUrl").orElse("https://docs.gradle.com/enterprise/api-manual/ref/")

val apiSpecificationFileGradleProperty = providers.gradleProperty("apiSpecificationFile")
val apiSpecificationURL = "${baseApiUrl.get()}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml"
etiennestuder marked this conversation as resolved.
Show resolved Hide resolved
val apiSpecificationFile = apiSpecificationFileGradleProperty
.map { s -> file(s) }
.orElse(objects.property(File::class)
.convention(provider {
resources.text.fromUri("${baseApiUrl.get()}gradle-enterprise-${gradleEnterpriseVersion}-api.yaml").asFile()
})
.orElse(
objects.property(File::class)
.convention(provider {
resources.text.fromUri(apiSpecificationURL).asFile()
})
).map { file -> file.absolutePath }

val basePackageName = "com.gradle.enterprise.api"
Expand Down Expand Up @@ -73,6 +82,16 @@ openApiGenerate {
))
}

tasks.named<Test>("test") {
maczikasz marked this conversation as resolved.
Show resolved Hide resolved
useJUnitPlatform()

systemProperties["ge.api.url"] = apiSpecificationURL

java {
sourceCompatibility = JavaVersion.VERSION_1_8
etiennestuder marked this conversation as resolved.
Show resolved Hide resolved
}
}

sourceSets {
main {
java {
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/com/gradle/enterprise/api/MockServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.gradle.enterprise.api;

import com.gradle.enterprise.api.client.ApiClient;
import com.gradle.enterprise.api.client.ApiException;
import com.gradle.enterprise.api.client.ServerConfiguration;
import com.gradle.enterprise.api.model.Build;
import com.gradle.enterprise.api.model.BuildsQuery;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockserver.configuration.Configuration;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.logging.MockServerLogger;
import org.mockserver.mock.Expectation;
import org.mockserver.openapi.OpenAPIConverter;

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;

public class MockServer {

private static final String gradleEnterpriseAPIYamlUrl = System.getProperty("ge.api.url");

private ClientAndServer mockServer;

@BeforeEach
public void setup() {
Configuration configuration = Configuration.configuration();
List<Expectation> openApiExpectations = new OpenAPIConverter(new MockServerLogger()).buildExpectations(gradleEnterpriseAPIYamlUrl, null);
mockServer = ClientAndServer.startClientAndServer(configuration, Collections.singletonList(19234));
mockServer.upsert(openApiExpectations.toArray(new Expectation[0]));
}

@Test
public void testSimpleAPICall() throws ApiException {
InetSocketAddress remoteAddress = mockServer.remoteAddress();

ApiClient apiClient = new ApiClient();
apiClient.setServers(Collections.singletonList(new ServerConfiguration(
"http://" + remoteAddress.getHostName() + ":" + remoteAddress.getPort(), "mockServer", Collections.emptyMap()
)));
BuildsApi buildsApi = new BuildsApi(apiClient);
apiClient.addDefaultHeader("Authorization", "Bearer XYZ");

List<Build> builds = buildsApi.getBuilds(new BuildsQuery());

assert !builds.isEmpty();
c00ler marked this conversation as resolved.
Show resolved Hide resolved
}
}