Skip to content

Commit

Permalink
Merge pull request #2 from CognitiveJ/0.2.9
Browse files Browse the repository at this point in the history
0.2.9
  • Loading branch information
CognitiveJ authored Aug 19, 2016
2 parents 5ed34fe + ea74397 commit 6982c89
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.2.8 (20/08/2016)
- Bug fixes

# 0.2.8 (29/07/2016)
- Added request routing feature

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WSSimulator is an open source library that easily allows for you to simulate ext
**Getting Started**

* Java 8
* The dependency from JCenter or the Standalone [distro](https://github.com/CognitiveJ/wssimulator/releases/download/0.2.8/wssimulator-0.2.8.zip "Download Standalone Version")
* The dependency from JCenter or the Standalone [distro](https://github.com/CognitiveJ/wssimulator/releases/download/0.2.9/wssimulator-0.2.9.zip "Download Standalone Version")


To simulate web service calls, you first need to describe the simulation. This process is very easy as Simulations are created in a YAML format and you don't need to 'simulate' much to get start as the only required field for you to define is _path_ and WSSimulator will default the other options.
Expand Down Expand Up @@ -54,15 +54,15 @@ There are 2 ways to use WSSimulator; as a standalone application or as an embedd
WSSimulator is packaged here and supports been executed on both *nix & windows systems;
* For *nix systems
- Unizip the ws-simulator-0.2.8.zip file to a local directory
- Unizip the ws-simulator-0.2.9.zip file to a local directory
- Then Call:
```shell
./wssimulator <options>
```

* For Windows
- Unizip the ws-simulator-0.2.8.zip file to a local directory
- Unizip the ws-simulator-0.2.9.zip file to a local directory
- Then Call:
```shell
./wssimulator.bat <options>
Expand Down Expand Up @@ -96,7 +96,7 @@ repositories {
}
dependencies {
compile "cognitivej:wssimulator:0.2.8"
compile "cognitivej:wssimulator:0.2.9"
...
}
Expand All @@ -107,7 +107,7 @@ repositories {
<dependency>
<groupId>cognitivej</groupId>
<artifactId>wssimulator</artifactId>
<version>0.2.8</version>
<version>0.2.9</version>
<type>pom</type>
</dependency>
```
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/wssimulator/WSSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public final class WSSimulator {
* @param yamlString YAML as a String
*/
public static void addSimulation(@NotNull String yamlString) {
LOG.info("adding simulation string: {}", yamlString);
YamlToSimulation yamlToSimulation = new YamlToSimulation(yamlString);
wsSimulatorServiceManager.add(yamlToSimulation.simulatorSimulation());
}
Expand All @@ -237,6 +238,7 @@ public static void addSimulation(@NotNull String yamlString) {
* @param classpathLocation YAML location on classpath
*/
public static void addSimulationOnClasspath(@NotNull String classpathLocation) {
LOG.info("adding simulation on classpath: {}", classpathLocation);
YamlToSimulation yamlToSimulation = new YamlToSimulation(new File(WSSimulator.class.getResource(classpathLocation).getFile()));
wsSimulatorServiceManager.add(yamlToSimulation.simulatorSimulation());
}
Expand All @@ -259,6 +261,7 @@ public static int addSimulation(@NotNull WSSimulation WSSimulation) {
* @return the id of this simulation
*/
public static int addSimulation(@NotNull File echoSimulationAsYaml) {
LOG.info("adding simulation file: {}", echoSimulationAsYaml);
YamlToSimulation yamlToSimulation = new YamlToSimulation(echoSimulationAsYaml);
return addSimulation(yamlToSimulation.simulatorSimulation());
}
Expand All @@ -267,6 +270,7 @@ public static int addSimulation(@NotNull File echoSimulationAsYaml) {
* Shuts down the simulator
*/
public static void shutdown() {
LOG.info("Shutting down server");
wsSimulatorServiceManager.shutdown();
}

Expand All @@ -276,6 +280,7 @@ public static void shutdown() {
* @param port the port number
*/
public static void setPort(int port) {
LOG.info("setting port to {}", port);
Spark.port(port);
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/wssimulator/WSSimulatorServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import static spark.Spark.*;

Expand All @@ -227,6 +228,7 @@
public class WSSimulatorServiceManager {
private int counter = 0;
private Map<String, BaseHandler> handlers = new HashMap<>();
private Map<Integer, WSSimulation> validSimulations = new HashMap<>();

private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(WSSimulatorServiceManager.class);

Expand Down Expand Up @@ -268,7 +270,7 @@ private static WSSimulatorServiceManager startup() {
return new WSSimulatorServiceManager();
}

private Map<Integer, WSSimulation> validSimulations = new HashMap<>();


/**
* Adds and starts a web service simulator simulation
Expand Down Expand Up @@ -340,9 +342,10 @@ else if ("application/json".equals(wsSimulation.consumes))
* Shuts down the simulator.
*/
public void shutdown() {
LOG.info("Shutting down server");
Spark.stop();
validSimulations.clear();
handlers.clear();
counter=0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/wssimulator-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.8
0.2.9
Original file line number Diff line number Diff line change
Expand Up @@ -206,42 +206,54 @@
package wssimulator

import io.restassured.http.ContentType
import org.slf4j.Logger
import spock.lang.Specification

import static io.restassured.RestAssured.given
import static org.hamcrest.core.IsEqual.equalTo
import static org.slf4j.LoggerFactory.*

/**
* Tests reading all yaml files for XML files.
*/
class RouteFilterSimulationSpecification extends Specification {
private static final Logger LOG = getLogger(RouteFilterSimulationSpecification.class);

def "Validate the route filter feature"() {
setup:
LOG.info("Validate the route filter feature:setup")
int port = TestUtils.randomPort()
when:
WSSimulator.setPort(port)
when:
WSSimulator.addSimulation(new File(getClass().getResource("/route/route1.yml").toURI()))
WSSimulator.addSimulation(new File(getClass().getResource("/route/route2.yml").toURI()))
WSSimulator.addSimulation(new File(getClass().getResource("/route/route3.yml").toURI()))
then:
LOG.info("Validate the route filter feature:then")

given().port(port)
.contentType(ContentType.XML)
.body("This is just random test with Action1 contained within it")
.post("/publish").then().assertThat()
.statusCode(200).and().body(equalTo("FilteredByAction1"))
LOG.info("Validate the route filter feature:then-1")

given().port(port)
.contentType(ContentType.XML)
.body("This is just random test with Action2 contained within it")
.post("/publish").then().assertThat()
.statusCode(200).and().body(equalTo("FilteredByAction2"))
LOG.info("Validate the route filter feature:then-2")

given().port(port)
.contentType(ContentType.XML)
.body("This is just random test with Action3 contained within it")
.post("/publish").then().assertThat()
.statusCode(200).and().body(equalTo("FilteredByAction3"))
LOG.info("Validate the route filter feature:end")

cleanup:
LOG.info("Validate the route filter feature:cleanup")
WSSimulator.shutdown()
}

Expand Down
3 changes: 0 additions & 3 deletions src/test/groovy/wssimulator/SOAPTestSpecification.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ class SOAPTestSpecification extends Specification {
.body(new File(getClass().getResource("/soap/payload.xml").toURI()))
.post("/CurrencyConvertor.asmx").then().assertThat()
.statusCode(200)
println "THEN FINISHED!!"
cleanup:
println "CLEANUP STARTEE!!"

WSSimulator.shutdown()

}
Expand Down

0 comments on commit 6982c89

Please sign in to comment.