Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Feb 19, 2024
1 parent 1e39f50 commit 8759fb1
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
- "https://developers.pipedrive.com/docs/api/v1/openapi.yaml"
- "apisguru::twilio.com:api"
- "apisguru::docusign.net"
- "apisguru::github.com:api.github.com"
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
Expand Down
5 changes: 4 additions & 1 deletion it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
"./tests/Kiota.Builder.IntegrationTests/GeneratesUritemplateHints.yaml": {
"MockServerITFolder": "query-params"
},
"apisguru::github.com:api.github.com": {
"MockServerITFolder": "gh"
},
"apisguru::notion.com": {
"ExcludePatterns": [
{
Expand Down Expand Up @@ -325,4 +328,4 @@
}
]
}
}
}
74 changes: 74 additions & 0 deletions it/java/gh/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0"?>
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>io.kiota</groupId>
<artifactId>kiota-gh-api</artifactId>
<version>0.1.0-SNAPSHOT</version>

<properties>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>0.12.1</kiota-java.version>
</properties>

<dependencies>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-abstractions</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-json</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-text</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-form</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-multipart</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-http-okHttp</artifactId>
<version>${kiota-java.version}</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M9</version>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions it/java/gh/src/test/java/GHAPITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import apisdk.ApiClient;
import com.microsoft.kiota.ApiException;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
import com.microsoft.kiota.http.OkHttpRequestAdapter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

public class BasicAPITest {

@Test
void basicTest() throws Exception {
var adapter = new OkHttpRequestAdapter(new AnonymousAuthenticationProvider());
adapter.setBaseUrl("http://127.0.0.1:1080");
var client = new ApiClient(adapter);

client.repos().byOwnerId("my-owner").byReposId("my-repo").get();
client.repos().byTemplateOwner("my-template-owner").byTemplateRepo("my-repo").post(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,75 @@ public void SinglePathParametersAreDeduplicatedAndOrderIsRespected()
Assert.Equal("\\repos\\{owner-id}\\{repo-id}\\generate", resultNode.Path);
Assert.Equal("{+baseurl}/repos/{owner%2Did}/{repo%2Did}/generate", resultNode.GetUrlTemplate());
}
[Fact]
public void repro4085()
{
var document = new OpenApiDocument
{
Paths = new OpenApiPaths
{
["/path/{thingId}/abc/{second}"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses {
["200"] = new OpenApiResponse
{
Content = {
["application/json"] = new OpenApiMediaType
{
Schema = new OpenApiSchema {
Type = "string"
}
}
}
}
}
}
}
},
["/path/{differentThingId}/def/{second}"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses {
["200"] = new OpenApiResponse
{
Content = {
["application/json"] = new OpenApiMediaType
{
Schema = new OpenApiSchema {
Type = "string"
}
}
}
}
}
}
}
}
}
};
var mockLogger = new CountLogger<KiotaBuilder>();
var builder = new KiotaBuilder(mockLogger, new GenerationConfiguration { ClientClassName = "GitHub", ApiRootUrl = "https://localhost" }, _httpClient);
var node = builder.CreateUriSpace(document);
node.MergeIndexNodesAtSameLevel(mockLogger);

// Expected
var resultNode = GetChildNodeByPath(node, "path");
Assert.NotNull(resultNode);
Assert.Equal("\\path", resultNode.Path);

var thingId = GetChildNodeByPath(resultNode, "{thingId}");
Assert.Equal("\\path\\{thingId}", thingId.Path);
Assert.Equal("{+baseurl}/path/{thingId}", thingId.GetUrlTemplate());

var differentThingId = GetChildNodeByPath(resultNode, "{differentThingId}");
Assert.Equal("\\path\\{differentThingId}", differentThingId.Path);
Assert.Equal("{+baseurl}/path/{differentThingId}", differentThingId.GetUrlTemplate());
}
private static OpenApiUrlTreeNode GetChildNodeByPath(OpenApiUrlTreeNode node, string path)
{
var pathSegments = path.Split('/');
Expand Down

0 comments on commit 8759fb1

Please sign in to comment.