Skip to content

Commit 0aa2316

Browse files
committed
use Maven to start MockServer
1 parent c3c6226 commit 0aa2316

File tree

6 files changed

+88
-84
lines changed

6 files changed

+88
-84
lines changed

.github/workflows/integration-tests.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@ name: integration-tests
33
on:
44
workflow_dispatch:
55
push:
6-
branches: [main]
7-
paths-ignore:
8-
[
9-
"abstractions/**",
10-
"authentication/**",
11-
"serialization/**",
12-
"http/**",
13-
"**.md",
14-
".vscode/**",
15-
"**.svg",
16-
]
17-
pull_request:
18-
paths-ignore:
19-
[
20-
"abstractions/**",
21-
"authentication/**",
22-
"serialization/**",
23-
"http/**",
24-
"**.md",
25-
".vscode/**",
26-
"**.svg",
27-
]
6+
# TODO: Restore me
7+
# branches: [main]
8+
# paths-ignore:
9+
# [
10+
# "abstractions/**",
11+
# "authentication/**",
12+
# "serialization/**",
13+
# "http/**",
14+
# "**.md",
15+
# ".vscode/**",
16+
# "**.svg",
17+
# ]
18+
# pull_request:
19+
# paths-ignore:
20+
# [
21+
# "abstractions/**",
22+
# "authentication/**",
23+
# "serialization/**",
24+
# "http/**",
25+
# "**.md",
26+
# ".vscode/**",
27+
# "**.svg",
28+
# ]
2829

2930
concurrency:
3031
# Only run once for latest commit per ref and cancel other (previous) runs.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,5 +447,3 @@ reports/
447447
*.prefs
448448

449449
samples/
450-
/it/mockserver.jar
451-
/it/mockserver.pid

it/exec-cmd.ps1

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,34 @@ function Invoke-Call {
2828
}
2929
}
3030

31+
function Retry([Action]$action)
32+
{
33+
$attempts=10
34+
$sleepInSeconds=1
35+
do
36+
{
37+
try
38+
{
39+
$action.Invoke();
40+
break;
41+
}
42+
catch [Exception]
43+
{
44+
Write-Host $_.Exception.Message
45+
}
46+
$attempts--
47+
if ($attempts -gt 0) { sleep $sleepInSeconds }
48+
} while ($attempts -gt 0)
49+
}
50+
3151
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
3252
$testPath = Join-Path -Path $scriptPath -ChildPath $language
53+
$mockServerPath = Join-Path -Path $scriptPath -ChildPath "mockserver"
3354

3455
function Kill-MockServer {
35-
$mockServerPIDFile = Join-Path -Path $scriptPath -ChildPath "mockserver.pid"
36-
if (Test-Path $mockServerPIDFile -PathType Leaf) {
37-
$mockServerPID = Get-Content -Path $mockServerPIDFile
38-
Stop-Process -Force -Id $mockServerPID
39-
Remove-Item $mockServerPIDFile
40-
}
56+
Push-Location $mockServerPath
57+
mvn mockserver:stopForked
58+
Pop-Location
4159
}
4260

4361
$mockSeverITFolder = $null
@@ -54,8 +72,19 @@ if ($null -ne $descriptionValue) {
5472
Kill-MockServer
5573
# Start MockServer if needed
5674
if (!([string]::IsNullOrEmpty($mockSeverITFolder))) {
57-
$startMockserverScript = Join-Path -Path $scriptPath -ChildPath "start-mockserver.ps1"
58-
Invoke-Expression "$startMockserverScript -descriptionUrl $descriptionUrl"
75+
Push-Location $mockServerPath
76+
mvn mockserver:runForked
77+
Pop-Location
78+
79+
# Provision Mock server with the right spec
80+
$openapiUrl = $descriptionUrl
81+
if ($openapiUrl.StartsWith("./")) {
82+
$rootPath = Split-Path -parent $scriptPath
83+
$openapiUrl = $openapiUrl.replace("./", "file:$rootPath/", 1)
84+
}
85+
86+
# provision MockServer to mock the specific openapi description https://www.mock-server.com/mock_server/using_openapi.html#button_open_api_filepath
87+
Retry({Invoke-WebRequest -Method PUT -Body "{ `"specUrlOrPayload`": `"$openapiUrl`" }" -Uri http://localhost:1080/mockserver/openapi -ContentType application/json})
5988
}
6089

6190
Push-Location $testPath

it/java/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717

1818
<kiota-java.version>0.3.0</kiota-java.version>
19-
<mockserver.version>5.14.0</mockserver.version>
2019
</properties>
2120

2221
<dependencies>

it/mockserver/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
5+
xmlns="http://maven.apache.org/POM/4.0.0">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>io.kiota</groupId>
8+
<artifactId>kiota-mock-server</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
11+
<properties>
12+
<mockserver.version>5.14.0</mockserver.version>
13+
</properties>
14+
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.mock-server</groupId>
19+
<artifactId>mockserver-maven-plugin</artifactId>
20+
<version>${mockserver.version}</version>
21+
<configuration>
22+
<serverPort>1080</serverPort>
23+
<logLevel>DEBUG</logLevel>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
</project>

it/start-mockserver.ps1

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)