Skip to content

Very simple integration testing JUnit harness for 'java -jar' servers like WildFly Swarm and Spring Boot

License

Notifications You must be signed in to change notification settings

wavesoftware/java-gasper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gasper!

Build Status Coverage Status Codacy Badge SonarQube Quality Gate SonarQube Tech Debt Maven Central Join the chat at https://gitter.im/wavesoftware/java-gasper

Gasper is a very simple integration testing JUnit harness for java -jar servers like WildFly Swarm and Spring Boot.

WildFly Swarm Spring Boot

Gasper provides a simple to use JUnit TestRule that can be used to build integration tests with simple apps, like REST micro-services. You can configure Gasper easily with a builder interface. Gasper will start the application before test class and stop it after tests completes.

Gasper supports currently only Maven. The pom.xml file is used to read project configuration achieving zero configuration operation.

Usage

Gasper utilize your packaged application. It It means it should be used in integration tests that run after application is being packaged by build tool (Maven). Add this code to your pom.xml file (if you didn't done that before):

<build>
[..]
<plugins>
[..]
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19.1</version>
    <executions>
      <execution>
        <goals>
          <goal>integration-test</goal>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
[..]
</plugins>
[..]
</build>

Place your integration tests in classes that ends with *IT or *ITest.

WildFly Swarm configuration

@ClassRule
public static Gasper gasper = Gasper.configurations()
  .wildflySwarm()
  .build();

Spring Boot configuration

@ClassRule
public static Gasper gasper = Gasper.configurations()
  .springBoot()
  .build();

Before running GasperBuilder.build() method, you can reconfigure those default configurations to your needs.

Example test method (Unirest + JSONAssert)

Gasper is best to use with libraries like Unirest for fetching data and asserting HTTP/S statuses and JSON Assert to validate correctness of JSON output for REST services.

@Test
public void testGetRoot() throws UnirestException {
  // given
  String address = gasper.getAddress(); // Address to deployed app, running live on random port
  String expectedMessage = "WildFly Swarm!";

  // when
  HttpResponse<String> response = Unirest.get(address).asString();

  // then
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getBody()).field("hello").isEqualTo(expectedMessage); // JSON Assert
}

Additional configuration

To configure Gasper use GasperBuilder interface, for ex.:

private final int port = 11909;
private final String webContext = "/test";
private final String systemPropertyForPort = "swarm.http.port";

@ClassRule
public static Gasper gasper = Gasper.configure()
  .silentGasperMessages()
  .usingSystemPropertyForPort(systemPropertyForPort)
  .withSystemProperty("swarm.context.path", webContext)
  .withSystemProperty(systemPropertyForPort, String.valueOf(port))
  .withJVMOptions("-server", "-Xms1G", "-Xmx1G", "-XX:+UseConcMarkSweepGC")
  .withMaxStartupTime(100)
  .withMaxDeploymentTime(20)
  .withEnvironmentVariable("jdbc.password", "S3CreT!1")
  .withTestApplicationLoggingOnConsole()
  .usingPomFile(Paths.get("pom.xml"))
  .withArtifactPackaging("jar")
  .waitForWebContext(webContext)
  .withArtifactClassifier("swarm")
  .usingWebContextChecker(GasperBuilderTest::checkContext)
  .withPort(port)
  .build();

Installation

Maven

<dependency>
    <groupId>pl.wavesoftware</groupId>
    <artifactId>gasper</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

Contributing

Contributions are welcome!

To contribute, follow the standard git flow of:

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create new Pull Request

Even if you can't contribute code, if you have an idea for an improvement please open an issue.

Requirements

  • Java 8
  • Maven 3

Releases

  • 1.0.0 - codename: SkyMango
    • First publicly available release

About

Very simple integration testing JUnit harness for 'java -jar' servers like WildFly Swarm and Spring Boot

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages