Skip to content

Commit

Permalink
swisspost#162: added more cucumber scenarios, simplified cucumber ste…
Browse files Browse the repository at this point in the history
…ps, stabilized integration tests, shortened sleep time
  • Loading branch information
roggerj committed Sep 11, 2017
1 parent 684d617 commit 8f92375
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ script:
- ./gradlew build
# - ./gradlew gateleen-test:startServer (no logging, also waits for it to come up)
- nohup java -jar gateleen-playground/build/libs/playground.jar &
- sleep 15s
- sleep 5s
# - ./gradlew :gateleen-playground:uploadStaticFiles
- ./gradlew :gateleen-playground:uploadStaticFiles
- ./gradlew :gateleen-test:test -PuiTests -Dsel_chrome_driver=src/test/resources/chromedriver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,52 +78,52 @@
<div class="panel-body">
<div class="row">
<div class="col-md-3">
<button type="button" class="btn btn-primary btn-lg btn-block" id="psh"
<button type="button" class="btn btn-primary btn-lg btn-block" id="Place Single Hook"
ng-click="hookJs.install('hook-demo')">Place Single Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="psfh"
<button type="button" class="btn btn-primary btn-lg btn-block" id="Place Single Fetching Hook"
ng-click="hookJs.install('hook-demo', 'single')">Place Single Fetching Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="pch"
<button type="button" class="btn btn-primary btn-lg btn-block" id="Place Collection Hook"
ng-click="hookJs.install('messages/')">Place Collection Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="pcfh"
<button type="button" class="btn btn-primary btn-lg btn-block" id="Place Collection Fetching Hook"
ng-click="hookJs.install('messages/', 'collection')">Place Collection Fetching Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="rlh" ng-click="hookJs.remove()">
Remove Last Hook
<button type="button" class="btn btn-primary btn-lg btn-block" id="Remove Last Hook"
ng-click="hookJs.remove()">Remove Last Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="ps"
<button type="button" class="btn btn-primary btn-lg btn-block" id="PUT Single"
ng-click="hookJs.put('hook-demo')">PUT Single
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" id="pc"
<button type="button" class="btn btn-primary btn-lg btn-block" id="PUT Collection"
ng-click="hookJs.put('messages', true)">PUT Collection
</button>
</div>

<div class="col-md-9">
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-info btn-lg btn-block" id="cl"
<button type="button" class="btn btn-info btn-lg btn-block" id="Clear log"
ng-click="hookJs.clearLog()">Clear log
</button>
</div>

<div class="col-md-6">
<button type="button" class="btn btn-info btn-lg btn-block" id="cc"
<button type="button" class="btn btn-info btn-lg btn-block" id="Clear collection"
ng-click="hookJs.clearCollection('messages')">Clear collection
</button>
</div>
</div>
</br>
<div class="row" style="padding-right: 15px">
<ul class="list-group" ng-show="hookJs.messages" id="hjsm">
<ul class="list-group" ng-show="hookJs.messages" id="hookjs messages">
<li class="list-group-item" ng-repeat="message in hookJs.messages track by $index">
{{message.info}}{{message.text}}
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ public void testRouteWithStaticHeaders(TestContext context) {
.body(containsString("x-test1"))
.body(containsString("x-test2"))
);
// String body = get(routedResource).getBody().asString();
// Assert.assertTrue(body.contains("x-test1"));
// Assert.assertTrue(body.contains("x-test2"));

// unregister route
TestUtils.unregisterRoute(requestUrl);

Expand Down Expand Up @@ -148,8 +144,10 @@ public void testRouteWithValidPath(TestContext context) {

String body2 = "{ \"name\" : \"routePathTest\"}";
given().body(body2).put(routedResource).then().assertThat().statusCode(200);
when().get(routedResource).then().assertThat().body(containsString(body2));
when().get(checkTarget).then().assertThat().body(containsString(body2));
Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> {
when().get(routedResource).then().assertThat().body(containsString(body2));
when().get(checkTarget).then().assertThat().body(containsString(body2));
});

async.complete();
}
Expand Down Expand Up @@ -187,8 +185,10 @@ public void testRoute(TestContext context) {
*/
String body1 = "{ \"name\" : \"routeTest 1\"}";
given().body(body1).put(routedResource).then().assertThat().statusCode(200);
when().get(routedResource).then().assertThat().body(containsString(body1));
when().get(checkTarget).then().assertThat().statusCode(404);
Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> {
when().get(routedResource).then().assertThat().body(containsString(body1));
when().get(checkTarget).then().assertThat().statusCode(404);
});
delete(routedResource);

// -------
Expand All @@ -207,8 +207,13 @@ public void testRoute(TestContext context) {
*/
String body2 = "{ \"name\" : \"routeTest 2\"}";
given().body(body2).put(routedResource).then().assertThat().statusCode(200);
when().get(routedResource).then().assertThat().body(containsString(body2));
when().get(checkTarget).then().assertThat().body(containsString(body2));
Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> {
when().get(routedResource).then().assertThat().body(containsString(body2));
when().get(checkTarget).then().assertThat().body(containsString(body2));
});
//
// when().get(routedResource).then().assertThat().body(containsString(body2));
// when().get(checkTarget).then().assertThat().body(containsString(body2));

// -------

Expand All @@ -217,8 +222,11 @@ public void testRoute(TestContext context) {
* -------
*/
delete(routedResource).then().assertThat().statusCode(200);
when().get(routedResource).then().assertThat().statusCode(404);
when().get(checkTarget).then().assertThat().statusCode(404);
Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> {
when().get(routedResource).then().assertThat().statusCode(404);
when().get(checkTarget).then().assertThat().statusCode(404);
});


// -------

Expand All @@ -236,9 +244,11 @@ public void testRoute(TestContext context) {
*/
String body3 = "{ \"name\" : \"routeTest 3\"}";
given().body(body3).put(routedResource).then().assertThat().statusCode(200);
when().get(routedResource).then().assertThat().body(containsString(body3));
when().get(checkTarget).then().assertThat().statusCode(404);
delete(routedResource);
Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> {
when().get(routedResource).then().assertThat().body(containsString(body3));
when().get(checkTarget).then().assertThat().statusCode(404);
delete(routedResource);
});

// -------
async.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.swisspush.gateleen.hookjs;

import com.jayway.awaitility.Duration;
import cucumber.api.PendingException;
import cucumber.api.java.After;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
Expand All @@ -26,6 +27,11 @@ public class HookJsSteps {

private static WebDriver webDriver;

@After
public static void quitBrowser(){
webDriver.quit();
}

@Given("^Chrome has been started$")
public void chromeHasBeenStarted() throws Throwable {
System.setProperty("webdriver.chrome.driver", System.getProperty("sel_chrome_driver"));
Expand All @@ -35,42 +41,30 @@ public void chromeHasBeenStarted() throws Throwable {
@And("^the hook-js UI is displayed$")
public void theHookJsUIIsDisplayed() throws Throwable {
webDriver.get("http://localhost:7012/playground/hooktest.html");
// TODO: Check that page really is displayed.
given().await().atMost(Duration.TWO_SECONDS).until(() ->
webDriver.findElement(By.xpath("/html/body/div/div/div/div[1]")).getText(),
equalTo("Hook JS Demo")
);
}

@When("^we click on the button \"([^\"]*)\"$")
public void weClickOnTheButton(String button) throws Throwable {

String buttonId;

switch (button) {
case "Place Single Hook":
buttonId = "psh";
break;

case "PUT Single":
buttonId = "ps";
break;

default:
buttonId = button;
break;
}

public void weClickOnTheButton(String buttonId) throws Throwable {
WebElement webButton = webDriver.findElement(By.id(buttonId));
webButton.click();
}

@Then("^we see the message \"([^\"]*)\" on position (\\d+)$")
public void weSeeTheMessageOnPosition(String message, int indexOfMessage) throws Throwable {
@Then("^we see the message \"([^\"]*)\" at position (\\d+)$")
public void weSeeTheMessageAtPosition(String message, int indexOfMessage) throws Throwable {
given().await().atMost(Duration.TWO_SECONDS).until(() ->
webDriver.findElement(By.xpath("//*[@id=\"hjsm\"]/li[" + indexOfMessage + "]")).getText(),
webDriver.findElement(By.xpath("//*[@id=\"hookjs messages\"]/li[" + indexOfMessage + "]")).getText(),
equalTo(message));
}

@After
public static void quitBrowser(){
webDriver.quit();
}

@Then("^we see no message at position (\\d+)$")
public void weSeeNoMessageAtPosition(int indexOfMessage) throws Throwable {
given().await().atMost(Duration.TWO_SECONDS).until(() ->
webDriver.findElements(By.xpath("//*[@id=\"hookjs messages\"]/li[" + indexOfMessage + "]")).size(),
equalTo(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,66 @@ Feature: hook-js UI Test
Given Chrome has been started
And the hook-js UI is displayed

Scenario: Place a sinlge hook and put single
Scenario: Place a single hook and put a single PUT
When we click on the button "Place Single Hook"
Then we see the message "Installing listener 1" on position 1
Then we see the message "Installing listener 1" at position 1
When we click on the button "PUT Single"
Then we see the message "Listener 1 received:<Message 1>" on position 2
Then we see the message "Listener 1 received:<Message 1>" at position 2

Scenario: Place a collection hook and put a collection of PUTs
When we click on the button "Place Collection Hook"
Then we see the message "Installing listener 1" at position 1
When we click on the button "PUT Collection"
Then we see the message "Listener 1 received:[resource-1] <Message 1>" at position 2

Scenario: Put a single PUT and place a single fetching hook
When we click on the button "PUT Single"
And we click on the button "Place Single Fetching Hook"
Then we see the message "Installing listener 1" at position 1
And we see the message "Listener 1 received:<Message 1>" at position 2

Scenario: Put a collection of PUTs and place a collection fetching hook
When we click on the button "PUT Collection"
And we click on the button "Place Collection Fetching Hook"
Then we see the message "Installing listener 1" at position 1
And we see the message "Listener 1 received:[resource-1] <Message 1>" at position 2

Scenario: Remove last hook
Given we click on the button "Place Single Hook"
And we see the message "Installing listener 1" at position 1
And we click on the button "PUT Single"
And we see the message "Listener 1 received:<Message 1>" at position 2
When we click on the button "Remove Last Hook"
Then we see the message "Removing listener 1" at position 3
When we click on the button "PUT Single"
Then we see no message at position 4

Scenario: Clear log
Given we click on the button "Place Single Hook"
And we see the message "Installing listener 1" at position 1
And we click on the button "PUT Single"
And we see the message "Listener 1 received:<Message 1>" at position 2
When we click on the button "Clear log"
Then we see no message at position 1
And we see no message at position 2

Scenario: Clear collection
Given we click on the button "PUT Collection"
And we click on the button "Place Collection Fetching Hook"
And we see the message "Installing listener 1" at position 1
And we see the message "Listener 1 received:[resource-1] <Message 1>" at position 2
When we click on the button "Clear collection"
And we click on the button "Place Collection Fetching Hook"
Then we see the message "Installing listener 2" at position 3
And we see no message at position 4











0 comments on commit 8f92375

Please sign in to comment.