Skip to content

Commit

Permalink
Use WireMock in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Nov 17, 2024
1 parent 922e838 commit ef8604a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 130 deletions.
39 changes: 5 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,40 +435,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.littleshoot</groupId>
<artifactId>littleproxy</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>LittleProxyStart</id>
<goals>
<goal>execute</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<source>${project.basedir}/src/build/scripts/LittleProxyStart.groovy</source>
</configuration>
</execution>
<execution>
<id>LittleProxyStop</id>
<goals>
<goal>execute</goal>
</goals>
<phase>post-integration-test</phase>
<configuration>
<source>System.setProperty('LittleProxy.stop', 'true'); Thread.sleep(250)</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
Expand Down Expand Up @@ -501,6 +467,11 @@
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.9.2</version>
</dependency>
</dependencies>
<executions>
<execution>
Expand Down
93 changes: 0 additions & 93 deletions src/build/scripts/LittleProxyStart.groovy

This file was deleted.

3 changes: 3 additions & 0 deletions src/it/download-licenses-proxy/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ invoker.settingsFile = src/it/settings-proxy.xml

# execute as last test, all needed artifact should be resolved before this test
invoker.ordinal = -100

# wiremock requires 11+
invoker.java.version = 11+
11 changes: 8 additions & 3 deletions src/it/download-licenses-proxy/postbuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
* #L%
*/

import java.nio.file.Path;
import java.nio.file.Files;
import com.github.tomakehurst.wiremock.WireMockServer

import java.nio.file.Files
import java.nio.file.Path

final Path basePath = basedir.toPath()

final Path asl2 = basePath.resolve('target/generated-resources/licenses/apache license 2.0 - license-2.0.txt')
assert Files.exists(asl2)
assert asl2.toFile().text.contains('Proxied via LittleProxy')
assert asl2.toFile().text.contains('Proxied via WireMock')

final Path expectedLicensesXml = basePath.resolve('licenses.expected.xml')
final Path licensesXml = basePath.resolve('target/generated-resources/licenses.xml')
assert expectedLicensesXml.toFile().text.equals(licensesXml.toFile().text)

WireMockServer wireMockServer = context.get("wireMockServer")
wireMockServer.stop()
47 changes: 47 additions & 0 deletions src/it/download-licenses-proxy/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.github.tomakehurst.wiremock.client.WireMock

/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit, Tony chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.common.ConsoleNotifier

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo
import static com.github.tomakehurst.wiremock.client.WireMock.get
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor

WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options()
.port(18080)
.notifier(new ConsoleNotifier(false)))
wireMockServer.start()

configureFor(wireMockServer.port())

stubFor(get('/licenses/LICENSE-2.0.txt')
.withHeader('Host', equalTo('www.apache.org'))
.willReturn(aResponse().withStatus(200).withBody('Proxied via WireMock')))

context.put("wireMockServer", wireMockServer)
true

0 comments on commit ef8604a

Please sign in to comment.