Skip to content

Commit 87c4816

Browse files
committed
Jvadocs and cycle fix
1 parent 19e9703 commit 87c4816

7 files changed

Lines changed: 475 additions & 193 deletions

File tree

README.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,41 @@ Gasper is a very simple integration testing JUnit harness for `java -jar` server
66

77
[![WildFly Swarm](https://avatars3.githubusercontent.com/u/11523816?v=3&s=100)](http://wildfly-swarm.io/) [![Spring Boot](https://avatars2.githubusercontent.com/u/317776?v=3&s=100)](http://projects.spring.io/spring-boot/)
88

9-
Gasper provides a simple to use JUnit `TestRule` that can be used to build integration tests with simple apps, like micro-services. You can configure Gasper with easy to use builder interface.
9+
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.
10+
11+
Gasper supports currently only [Maven](https://maven.apache.org/). The `pom.xml` file is used to read project configuration achieving zero configuration operation.
1012

1113
## Usage
1214

13-
Best to use with libraries like [Unirest](http://unirest.io/java.html) and [JSON Assert](https://github.com/marcingrzejszczak/jsonassert)
15+
16+
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):
17+
18+
```xml
19+
<build>
20+
[..]
21+
<plugins>
22+
[..]
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-failsafe-plugin</artifactId>
26+
<version>2.19.1</version>
27+
<executions>
28+
<execution>
29+
<goals>
30+
<goal>integration-test</goal>
31+
<goal>verify</goal>
32+
</goals>
33+
</execution>
34+
</executions>
35+
</plugin>
36+
[..]
37+
</plugins>
38+
[..]
39+
</build>
40+
```
41+
42+
43+
Place your integration tests in classes that ends with `*IT` or `*ITest`.
1444

1545
### WildFly Swarm configuration
1646

@@ -30,21 +60,25 @@ public static Gasper gasper = Gasper.configurations()
3060
.build();
3161
```
3262

63+
Before running `GasperBuilder.build()` method, you can reconfigure those default configurations to your needs.
64+
3365
### Example test method (Unirest + JSONAssert)
3466

67+
Gasper is best to use with libraries like [Unirest](http://unirest.io/java.html) for fetching data and asserting HTTP/S statuses and [JSON Assert](https://github.com/marcingrzejszczak/jsonassert) to validate correctness of JSON output for REST services.
68+
3569
```java
3670
@Test
3771
public void testGetRoot() throws UnirestException {
3872
// given
39-
String address = gasper.getAddress();
73+
String address = gasper.getAddress(); // Address to deployed app, running live on random port
4074
String expectedMessage = "WildFly Swarm!";
4175

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

4579
// then
4680
assertThat(response.getStatus()).isEqualTo(200);
47-
assertThat(response.getBody()).field("hello").isEqualTo(expectedMessage);
81+
assertThat(response.getBody()).field("hello").isEqualTo(expectedMessage); // JSON Assert
4882
}
4983
```
5084

@@ -56,6 +90,7 @@ To configure Gasper use `GasperBuilder` interface, for ex.:
5690
private final int port = 11909;
5791
private final String webContext = "/test";
5892
private final String systemPropertyForPort = "swarm.http.port";
93+
5994
@ClassRule
6095
public static Gasper gasper = Gasper.configure()
6196
.silentGasperMessages()
@@ -66,7 +101,7 @@ public static Gasper gasper = Gasper.configure()
66101
.withMaxStartupTime(100)
67102
.withMaxDeploymentTime(20)
68103
.withEnvironmentVariable("jdbc.password", "S3CreT!1")
69-
.withServerLoggingOnConsole()
104+
.withTestApplicationLoggingOnConsole()
70105
.usingPomFile(Paths.get("pom.xml"))
71106
.withArtifactPackaging("jar")
72107
.waitForWebContext(webContext)
@@ -89,7 +124,26 @@ public static Gasper gasper = Gasper.configure()
89124
</dependency>
90125
```
91126

127+
## Contributing
128+
129+
Contributions are welcome!
130+
131+
To contribute, follow the standard [git flow](http://danielkummer.github.io/git-flow-cheatsheet/) of:
132+
133+
1. Fork it
134+
1. Create your feature branch (`git checkout -b feature/my-new-feature`)
135+
1. Commit your changes (`git commit -am 'Add some feature'`)
136+
1. Push to the branch (`git push origin feature/my-new-feature`)
137+
1. Create new Pull Request
138+
139+
Even if you can't contribute code, if you have an idea for an improvement please open an [issue](https://github.com/wavesoftware/java-gasper/issues).
140+
92141
## Requirements
93142

94-
Gasper requires Java 8. Tested on Travis CI.
143+
* Java 8
144+
* Maven 3
145+
146+
## Releases
95147

148+
* `1.0.0` - codename: *SkyMango*
149+
* First publicly available release

src/main/java/pl/wavesoftware/gasper/Gasper.java

Lines changed: 136 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.junit.runner.Description;
1010
import org.junit.runners.model.Statement;
1111
import pl.wavesoftware.eid.utils.EidPreconditions;
12-
import pl.wavesoftware.gasper.internal.AbstractGasperBuilder;
1312
import pl.wavesoftware.gasper.internal.Executor;
1413
import pl.wavesoftware.gasper.internal.Logger;
1514
import pl.wavesoftware.gasper.internal.Settings;
@@ -28,6 +27,119 @@
2827
import static pl.wavesoftware.eid.utils.EidPreconditions.tryToExecute;
2928

3029
/**
30+
* <h2>About</h2>
31+
* Gasper is a very simple integration testing JUnit harness for <code>java -jar</code> servers like <a href="http://wildfly-swarm.io/">WildFly Swarm</a> and <a href="http://projects.spring.io/spring-boot/">Spring Boot</a>.
32+
* <p>
33+
* Gasper provides a simple to use JUnit {@link 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.
34+
* <p>
35+
* Gasper supports currently only <a href="https://maven.apache.org/">Maven</a>. The <code>pom.xml</code> file is used to read project configuration achieving zero configuration operation.
36+
*
37+
* <h3>Usage</h3>
38+
*
39+
* 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 <code>pom.xml</code> file (if you didn't done that before):
40+
*
41+
* <pre>
42+
* &lt;build&gt;
43+
* [..]
44+
* &lt;plugins&gt;
45+
* [..]
46+
* &lt;plugin&gt;
47+
* &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
48+
* &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
49+
* &lt;version&gt;2.19.1&lt;/version&gt;
50+
* &lt;executions&gt;
51+
* &lt;execution&gt;
52+
* &lt;goals&gt;
53+
* &lt;goal&gt;integration-test&lt;/goal&gt;
54+
* &lt;goal&gt;verify&lt;/goal&gt;
55+
* &lt;/goals&gt;
56+
* &lt;/execution&gt;
57+
* &lt;/executions&gt;
58+
* &lt;/plugin&gt;
59+
* [..]
60+
* &lt;/plugins&gt;
61+
* [..]
62+
* &lt;/build&gt;
63+
* </pre>
64+
*
65+
* Place your integration tests in classes that ends with <code>*IT</code> or <code>*ITest</code>.
66+
*
67+
* <h4>WildFly Swarm default configuration</h4>
68+
*
69+
* <pre>
70+
* &#064;ClassRule
71+
* public static Gasper gasper = Gasper.configurations()
72+
* .wildflySwarm()
73+
* .build();
74+
* </pre>
75+
*
76+
* <h4>Spring Boot default configuration</h4>
77+
*
78+
* <pre>
79+
* &#064;ClassRule
80+
* public static Gasper gasper = Gasper.configurations()
81+
* .springBoot()
82+
* .build();
83+
* </pre>
84+
* <p>
85+
* Before running {@link GasperBuilder#build()} method, you can reconfigure those default configurations to your needs.
86+
*
87+
* <h4>Example test method (Unirest + JSONAssert)</h4>
88+
*
89+
* Gasper is best to use with libraries like <a href="http://unirest.io/java.html">Unirest</a> for fetching
90+
* data and asserting HTTP/S statuses and <a href="https://github.com/marcingrzejszczak/jsonassert">JSON
91+
* Assert</a> to validate correctness of JSON output for REST services.
92+
*
93+
* <pre>
94+
* &#064;Test
95+
* public void testGetRoot() throws UnirestException {
96+
* // given
97+
* String address = gasper.getAddress(); // Address to deployed app, running live on random port
98+
* String expectedMessage = "WildFly Swarm!";
99+
* // when
100+
* HttpResponse<String> response = Unirest.get(address).asString();
101+
* // then
102+
* assertThat(response.getStatus()).isEqualTo(200);
103+
* assertThat(response.getBody()).field("hello").isEqualTo(expectedMessage); // JSON Assert
104+
* }
105+
* </pre>
106+
*
107+
* <h4>Additional configuration</h4>
108+
*
109+
* To configure Gasper use {@link GasperBuilder} interface, for ex.:
110+
*
111+
* <pre>
112+
* private final int port = 11909;
113+
* private final String webContext = "/test";
114+
* private final String systemPropertyForPort = "swarm.http.port";
115+
*
116+
* &#064;ClassRule
117+
* public static Gasper gasper = Gasper.configure()
118+
* .silentGasperMessages()
119+
* .usingSystemPropertyForPort(systemPropertyForPort)
120+
* .withSystemProperty("swarm.context.path", webContext)
121+
* .withSystemProperty(systemPropertyForPort, String.valueOf(port))
122+
* .withJVMOptions("-server", "-Xms1G", "-Xmx1G", "-XX:+UseConcMarkSweepGC")
123+
* .withMaxStartupTime(100)
124+
* .withMaxDeploymentTime(20)
125+
* .withEnvironmentVariable("jdbc.password", "S3CreT!1")
126+
* .withTestApplicationLoggingOnConsole()
127+
* .usingPomFile(Paths.get("pom.xml"))
128+
* .withArtifactPackaging("jar")
129+
* .waitForWebContext(webContext)
130+
* .withArtifactClassifier("swarm")
131+
* .usingWebContextChecker(GasperBuilderTest::checkContext)
132+
* .withPort(port)
133+
* .build();
134+
* </pre>
135+
*
136+
* <h4>Requirements</h4>
137+
*
138+
* <ul>
139+
* <li>Java 8</li>
140+
* <li>Maven 3</li>
141+
* </ul>
142+
*
31143
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
32144
* @since 2016-03-04
33145
*/
@@ -54,31 +166,40 @@ public final class Gasper implements TestRule {
54166
/**
55167
* Creates a builder interface {@link GasperBuilder} that can be used to configure Gasper.
56168
* <p>
57-
* You can also use already created configurations by using method {@link #configurations()} for convenience.
169+
* You can also use, already created, configurations by using method {@link #configurations()} for
170+
* convenience.
58171
* @return a configure interface for configuration purposes
59172
*/
60173
public static GasperBuilder configure() {
61-
return new GasperBuilderImpl();
174+
return new GasperBuilder();
62175
}
63176

177+
/**
178+
* Retrieves {@link GasperConfigurations} which hold some pre configured {@link GasperBuilder} instances
179+
* and can be used for convenience.
180+
* @return a pre configured configurations
181+
*/
64182
public static GasperConfigurations configurations() {
65183
return new GasperConfigurations();
66184
}
67185

186+
/**
187+
* Use this method to get port on which Gasper runs your test application.
188+
* @return a usually random port on which Gasper runs your application
189+
*/
68190
public Integer getPort() {
69191
return settings.getPort();
70192
}
71193

194+
/**
195+
* Use this method to get full address to your test application that Gasper runs. It usually
196+
* contains a random port.
197+
* @return a full address to running application
198+
*/
72199
public String getAddress() {
73200
return settings.getEndpoint().fullAddress();
74201
}
75202

76-
protected interface RunnerCreator {
77-
default Gasper create(Settings settings) {
78-
return new Gasper(settings);
79-
}
80-
}
81-
82203
@Override
83204
public Statement apply(Statement base, Description description) {
84205
return tryToExecute((EidPreconditions.UnsafeSupplier<Statement>) () -> {
@@ -88,6 +209,12 @@ public Statement apply(Statement base, Description description) {
88209
}, "20160305:004035");
89210
}
90211

212+
protected interface RunnerCreator {
213+
default Gasper create(Settings settings) {
214+
return new Gasper(settings);
215+
}
216+
}
217+
91218
private void setup() {
92219
log(FIGLET);
93220
MavenResolver resolver = new MavenResolver(settings.getPomfile());
@@ -155,8 +282,4 @@ private void ensureLogger() {
155282
logger = new Logger(log, settings);
156283
}
157284
}
158-
159-
private static class GasperBuilderImpl extends AbstractGasperBuilder {
160-
161-
}
162285
}

0 commit comments

Comments
 (0)