SoapUI JUnit MockRunner

This JUnit extension will bootstrap SoapUI Mock in its own classloader context to prevent clashes with any project dependencies that are under test. The mockrunner uses Plexus Classworlds/Container and Aether to decouple the execution of the mock from the projects under test.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

io.fares.junit.soapui
ArtifactId

ArtifactId

soapui-junit-mockrunner
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

SoapUI JUnit MockRunner
This JUnit extension will bootstrap SoapUI Mock in its own classloader context to prevent clashes with any project dependencies that are under test. The mockrunner uses Plexus Classworlds/Container and Aether to decouple the execution of the mock from the projects under test.

Download soapui-junit-mockrunner

How to add to project

<!-- https://jarcasting.com/artifacts/io.fares.junit.soapui/soapui-junit-mockrunner/ -->
<dependency>
    <groupId>io.fares.junit.soapui</groupId>
    <artifactId>soapui-junit-mockrunner</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.fares.junit.soapui/soapui-junit-mockrunner/
implementation 'io.fares.junit.soapui:soapui-junit-mockrunner:0.0.3'
// https://jarcasting.com/artifacts/io.fares.junit.soapui/soapui-junit-mockrunner/
implementation ("io.fares.junit.soapui:soapui-junit-mockrunner:0.0.3")
'io.fares.junit.soapui:soapui-junit-mockrunner:jar:0.0.3'
<dependency org="io.fares.junit.soapui" name="soapui-junit-mockrunner" rev="0.0.3">
  <artifact name="soapui-junit-mockrunner" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.fares.junit.soapui', module='soapui-junit-mockrunner', version='0.0.3')
)
libraryDependencies += "io.fares.junit.soapui" % "soapui-junit-mockrunner" % "0.0.3"
[io.fares.junit.soapui/soapui-junit-mockrunner "0.0.3"]

Dependencies

compile (15)

Group / Artifact Type Version
org.unitils : unitils-core jar 3.4.2
junit : junit jar 4.11
org.eclipse.sisu : org.eclipse.sisu.inject jar 0.1.1
org.eclipse.sisu : org.eclipse.sisu.plexus jar 0.1.1
org.sonatype.sisu : sisu-guice jar 3.1.6
org.codehaus.plexus : plexus-utils jar 2.1
org.eclipse.aether : aether-api jar 1.0.0.v20140518
org.eclipse.aether : aether-spi jar 1.0.0.v20140518
org.eclipse.aether : aether-util jar 1.0.0.v20140518
org.eclipse.aether : aether-impl jar 1.0.0.v20140518
org.eclipse.aether : aether-connector-basic jar 1.0.0.v20140518
org.eclipse.aether : aether-transport-file jar 1.0.0.v20140518
org.eclipse.aether : aether-transport-http jar 1.0.0.v20140518
org.apache.maven : maven-settings-builder jar 3.1.0
org.apache.maven : maven-aether-provider jar 3.1.0

provided (2)

Group / Artifact Type Version
com.smartbear.soapui » soapui jar 5.2.1
xmlbeans : xbean jar fixed-2.4.0

test (6)

Group / Artifact Type Version
commons-io : commons-io jar 2.4
org.slf4j : slf4j-api jar 1.7.2
org.slf4j : jcl-over-slf4j jar 1.7.2
org.slf4j : jul-to-slf4j jar 1.7.2
org.slf4j : slf4j-log4j12 jar 1.7.2
log4j : log4j jar 1.2.17

Project Modules

There are no modules declared in this project.

SoapUI JUnit MockRunner

Overview

Ever tried to start a soapui mock service from within your junit test? Sure the soapui-maven-plugin make a good job when you just run from command line ... but if you develop in an IDE that is not always the case.

This module can be used to execute a soapui mock service within a classloader jail. This will ensure the project under test is not dependent on SoapUI itself. The classloader jail will resolve all required dependencies from the official soapui maven repository.

Example

The most simple example on how to fire up a Junit test with a SoapUI mock service running in the background.

import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Test;

public class SomeMockServiceTest {

  @ClassRule
  public static SoapUIMockRunner runner = new SoapUIMockRunner()
                                                  .simpleBinding()
                                                  .withProjectPath("embedded-soapui/TestSoapUIProject-soapui-project.xml")
                                                  .withMockServiceName("WeatherMockService")
                                                  .withMockHost("localhost")
                                                  .withMockPort(8097)
                                                  .withMockPath("/weather-change");

  @Test
  public void testMockRunner() throws Exception {
    assertTrue(runner.isRunning());
    System.out.println("do some testing against endpoint: " + runner.getMockEndpoint());
  }

}

Configure SoapUI Version

Because the soapui starts in a classloader jail, one can also a) compile this libary against a different version:

mvn clean install -Dsoapui.version=5.1.2

or if the compiled version of soapui-junit-mockrunner is largely compatible with what you are trying to run, simply specify the version on the SoapUIMockRunner:

new SoapUIMockRunner()
        .simpleBinding()
        .withProjectPath("embedded-soapui/TestSoapUIProject-soapui-project.xml")
        .withMockServiceName("WeatherMockService")
        .soapuiVersion("5.1.2");

The option is risky when you specify a runner version that is incompatible with the soapui classes that are loaded.

I sucessfully ran a soapui-junit-mockrunner compiled against SoapUI 5.0.0 using a 5.1.2 runtime version (as above example).

TODO

Instead of the dodgy simple binding, should really use com.eviware.soapui.tools.SoapUIMockServiceRunner.main() with a set of standard SoapUI path parameters.

Limitiations

  1. the reflection binding does not work with path, port and host settings (use simple binding)
  2. searching for the local maven repo for cached artefact bindings is rather crude
  3. need to improve exception handing, especially with the rule
  4. not enough tests and examples

Versions

Version
0.0.3
0.0.2