Skip to content

Commit

Permalink
use Maven to start MockServer
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Mar 28, 2023
1 parent c3c6226 commit 0aa2316
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 84 deletions.
45 changes: 23 additions & 22 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ name: integration-tests
on:
workflow_dispatch:
push:
branches: [main]
paths-ignore:
[
"abstractions/**",
"authentication/**",
"serialization/**",
"http/**",
"**.md",
".vscode/**",
"**.svg",
]
pull_request:
paths-ignore:
[
"abstractions/**",
"authentication/**",
"serialization/**",
"http/**",
"**.md",
".vscode/**",
"**.svg",
]
# TODO: Restore me
# branches: [main]
# paths-ignore:
# [
# "abstractions/**",
# "authentication/**",
# "serialization/**",
# "http/**",
# "**.md",
# ".vscode/**",
# "**.svg",
# ]
# pull_request:
# paths-ignore:
# [
# "abstractions/**",
# "authentication/**",
# "serialization/**",
# "http/**",
# "**.md",
# ".vscode/**",
# "**.svg",
# ]

concurrency:
# Only run once for latest commit per ref and cancel other (previous) runs.
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,3 @@ reports/
*.prefs

samples/
/it/mockserver.jar
/it/mockserver.pid
45 changes: 37 additions & 8 deletions it/exec-cmd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,34 @@ function Invoke-Call {
}
}

function Retry([Action]$action)
{
$attempts=10
$sleepInSeconds=1
do
{
try
{
$action.Invoke();
break;
}
catch [Exception]
{
Write-Host $_.Exception.Message
}
$attempts--
if ($attempts -gt 0) { sleep $sleepInSeconds }
} while ($attempts -gt 0)
}

$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$testPath = Join-Path -Path $scriptPath -ChildPath $language
$mockServerPath = Join-Path -Path $scriptPath -ChildPath "mockserver"

function Kill-MockServer {
$mockServerPIDFile = Join-Path -Path $scriptPath -ChildPath "mockserver.pid"
if (Test-Path $mockServerPIDFile -PathType Leaf) {
$mockServerPID = Get-Content -Path $mockServerPIDFile
Stop-Process -Force -Id $mockServerPID
Remove-Item $mockServerPIDFile
}
Push-Location $mockServerPath
mvn mockserver:stopForked
Pop-Location
}

$mockSeverITFolder = $null
Expand All @@ -54,8 +72,19 @@ if ($null -ne $descriptionValue) {
Kill-MockServer
# Start MockServer if needed
if (!([string]::IsNullOrEmpty($mockSeverITFolder))) {
$startMockserverScript = Join-Path -Path $scriptPath -ChildPath "start-mockserver.ps1"
Invoke-Expression "$startMockserverScript -descriptionUrl $descriptionUrl"
Push-Location $mockServerPath
mvn mockserver:runForked
Pop-Location

# Provision Mock server with the right spec
$openapiUrl = $descriptionUrl
if ($openapiUrl.StartsWith("./")) {
$rootPath = Split-Path -parent $scriptPath
$openapiUrl = $openapiUrl.replace("./", "file:$rootPath/", 1)
}

# provision MockServer to mock the specific openapi description https://www.mock-server.com/mock_server/using_openapi.html#button_open_api_filepath
Retry({Invoke-WebRequest -Method PUT -Body "{ `"specUrlOrPayload`": `"$openapiUrl`" }" -Uri http://localhost:1080/mockserver/openapi -ContentType application/json})
}

Push-Location $testPath
Expand Down
1 change: 0 additions & 1 deletion it/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>0.3.0</kiota-java.version>
<mockserver.version>5.14.0</mockserver.version>
</properties>

<dependencies>
Expand Down
28 changes: 28 additions & 0 deletions it/mockserver/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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-mock-server</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<mockserver.version>5.14.0</mockserver.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>${mockserver.version}</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
</configuration>
</plugin>
</plugins>
</build>
</project>
51 changes: 0 additions & 51 deletions it/start-mockserver.ps1

This file was deleted.

0 comments on commit 0aa2316

Please sign in to comment.