diff --git a/.travis.yml b/.travis.yml
index 1a00cb804..830d081b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/gateleen-playground/src/main/resources/playground/server/pages/hooktest.html b/gateleen-playground/src/main/resources/playground/server/pages/hooktest.html
index 3aad7e932..ab02194dc 100644
--- a/gateleen-playground/src/main/resources/playground/server/pages/hooktest.html
+++ b/gateleen-playground/src/main/resources/playground/server/pages/hooktest.html
@@ -78,31 +78,31 @@
-
-
-
-
-
@@ -110,20 +110,20 @@
- Clear log
- Clear collection
-
+
{{message.info}}{{message.text}}
diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/hook/RouteTest.java b/gateleen-test/src/test/java/org/swisspush/gateleen/hook/RouteTest.java
index 96fe22be9..8568c7f1d 100644
--- a/gateleen-test/src/test/java/org/swisspush/gateleen/hook/RouteTest.java
+++ b/gateleen-test/src/test/java/org/swisspush/gateleen/hook/RouteTest.java
@@ -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);
@@ -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();
}
@@ -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);
// -------
@@ -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));
// -------
@@ -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);
+ });
+
// -------
@@ -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();
diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsSteps.java b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsSteps.java
index 70b56ff73..ee8481f7e 100644
--- a/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsSteps.java
+++ b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsSteps.java
@@ -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;
@@ -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"));
@@ -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));
+ }
}
diff --git a/gateleen-test/src/test/resources/org/swisspush/gateleen/hookjs/hook-js-ui-test.feature b/gateleen-test/src/test/resources/org/swisspush/gateleen/hookjs/hook-js-ui-test.feature
index 801233ac4..994ade8e4 100644
--- a/gateleen-test/src/test/resources/org/swisspush/gateleen/hookjs/hook-js-ui-test.feature
+++ b/gateleen-test/src/test/resources/org/swisspush/gateleen/hookjs/hook-js-ui-test.feature
@@ -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:" on position 2
+ Then we see the message "Listener 1 received:" 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] " 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:" 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] " 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:" 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:" 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] " 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
+
+
+
+
+
+
+
+
+
+
+