diff --git a/gateleen-test/build.gradle b/gateleen-test/build.gradle index 4440cd62c..374a572e8 100644 --- a/gateleen-test/build.gradle +++ b/gateleen-test/build.gradle @@ -47,14 +47,10 @@ dependencies { exclude group: 'org.seleniumhq.selenium', module: 'selenium-opera-driver' exclude group: 'org.seleniumhq.selenium', module: 'selenium-safari-driver' } + testCompile (group: 'info.cukes', name: 'cucumber-java', version: '1.2.5') + testCompile (group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5') } -//test { -// onlyIf { -// project.hasProperty("integrationTests") -// } -//} - test { onlyIf { project.hasProperty("nonUiTests") || project.hasProperty("uiTests") @@ -63,12 +59,16 @@ test { systemProperty "sel_chrome_driver", System.getProperty("sel_chrome_driver") filter { + if (project.hasProperty("nonUiTests")) { exclude "org/swisspush/gateleen/hookjs/**" include "org/swisspush/gateleen/**" } + if (project.hasProperty("uiTests")) { include "org/swisspush/gateleen/hookjs/**" } } + + outputs.upToDateWhen { false } } 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 7796ba780..96fe22be9 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 @@ -1,11 +1,12 @@ package org.swisspush.gateleen.hook; +import com.jayway.awaitility.Awaitility; +import com.jayway.awaitility.Duration; import com.jayway.restassured.RestAssured; import io.vertx.core.json.JsonObject; import io.vertx.ext.unit.Async; import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.swisspush.gateleen.AbstractTest; @@ -103,9 +104,16 @@ public void testRouteWithStaticHeaders(TestContext context) { TestUtils.registerRoute(requestUrl, target, methods, staticHeaders); // - String body = get(routedResource).getBody().asString(); - Assert.assertTrue(body.contains("x-test1")); - Assert.assertTrue(body.contains("x-test2")); + + Awaitility.given().await().atMost(Duration.TWO_SECONDS).until(() -> + when().get(routedResource).then().assertThat() + .statusCode(200) + .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); 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 new file mode 100644 index 000000000..5d5338fb0 --- /dev/null +++ b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsSteps.java @@ -0,0 +1,77 @@ +/* + * ------------------------------------------------------------------------------------------------ + * Copyright 2014 by Swiss Post, Information Technology Services + * ------------------------------------------------------------------------------------------------ + * $Id$ + * ------------------------------------------------------------------------------------------------ + */ + +package org.swisspush.gateleen.hookjs; + +import com.jayway.awaitility.Duration; +import cucumber.api.java.After; +import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; + +import static com.jayway.awaitility.Awaitility.given; +import static org.hamcrest.core.IsEqual.equalTo; + +public class HookJsSteps { + + private static WebDriver webDriver; + + @Given("^Chrome has been started$") + public void chromeHasBeenStarted() throws Throwable { + System.setProperty("sel_chrome_driver", "/home/jonas/work/jrepo-local/tools/chromedrivers/chromedriver2-32"); + System.setProperty("webdriver.chrome.driver", System.getProperty("sel_chrome_driver")); + webDriver = new ChromeDriver(); + } + + @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. + } + + @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; + } + + 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 { + given().await().atMost(Duration.TWO_SECONDS).until(() -> + webDriver.findElement(By.xpath("//*[@id=\"hjsm\"]/li[" + indexOfMessage + "]")).getText(), + equalTo(message)); + } + + @After + public static void quitBrowser(){ + webDriver.quit(); + } + +} diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsUITest.java b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsUITest.java deleted file mode 100644 index d405cf631..000000000 --- a/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/HookJsUITest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------ - * Copyright 2014 by Swiss Post, Information Technology Services - * ------------------------------------------------------------------------------------------------ - * $Id$ - * ------------------------------------------------------------------------------------------------ - */ - -package org.swisspush.gateleen.hookjs; - -import com.jayway.awaitility.Duration; -import org.junit.*; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.swisspush.gateleen.AbstractTest; - -import static com.jayway.awaitility.Awaitility.await; -import static org.hamcrest.core.IsEqual.equalTo; - -public class HookJsUITest { - - private static WebDriver webDriver; - - @BeforeClass - public static void setupChromeDriver() { - - -// if (System.getProperty("sel_chrome_driver") == null) { -// System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver"); -// } else { - System.setProperty("webdriver.chrome.driver", System.getProperty("sel_chrome_driver")); -// } - - webDriver = new ChromeDriver(); - } - - @Test - public void testSingleHook() throws InterruptedException { - - webDriver.get("http://localhost:7012/playground/hooktest.html"); - -// await().atMost(Duration.TWO_SECONDS).until(() -> -// webDriver.findElement(By.xpath("/html/body/pre")).getText(), -// equalTo("404 Not Found")); - - WebElement buttonPlaceSingleHook = webDriver.findElement(By.id("psh")); - buttonPlaceSingleHook.click(); - await().atMost(Duration.TWO_SECONDS).until(() -> - webDriver.findElement(By.xpath("//*[@id=\"hjsm\"]/li[1]")).getText(), - equalTo("Installing listener 1")); - - WebElement buttonPutSingle = webDriver.findElement(By.id("ps")); - buttonPutSingle.click(); - await().atMost(Duration.TWO_SECONDS).until(() -> - webDriver.findElement(By.xpath("//*[@id=\"hjsm\"]/li[2]")).getText(), - equalTo("Listener 1 received:")); - } - - @AfterClass - public static void afterClass(){ - webDriver.quit(); - } - -} diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/RunCucumberTests.java b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/RunCucumberTests.java new file mode 100644 index 000000000..1b3187ec2 --- /dev/null +++ b/gateleen-test/src/test/java/org/swisspush/gateleen/hookjs/RunCucumberTests.java @@ -0,0 +1,18 @@ +/* + * ------------------------------------------------------------------------------------------------ + * Copyright 2014 by Swiss Post, Information Technology Services + * ------------------------------------------------------------------------------------------------ + * $Id$ + * ------------------------------------------------------------------------------------------------ + */ + +package org.swisspush.gateleen.hookjs; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty"}) +public class RunCucumberTests { +} diff --git a/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java b/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java index 109c24dfc..59558f645 100644 --- a/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java +++ b/gateleen-test/src/test/java/org/swisspush/gateleen/routing/RequestHopValidationTest.java @@ -1,6 +1,7 @@ package org.swisspush.gateleen.routing; import com.google.common.collect.ImmutableMap; +import com.jayway.awaitility.Awaitility; import com.jayway.awaitility.Duration; import com.jayway.restassured.RestAssured; import io.vertx.core.json.JsonObject; @@ -80,19 +81,19 @@ public void testRequestHopValidationLimitExceeded(TestContext context) { when().get("/loop/4/resource").then().assertThat().statusCode(200); // get the test data via looping rules - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> when().get("/loop/1/resource").then().assertThat() .statusCode(500) .statusLine(containsString("Request hops limit exceeded")) .body(containsString(buildLimitExceededMessage(2))) ); - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> when().get("/loop/2/resource").then().assertThat() .statusCode(500) .statusLine(containsString("Request hops limit exceeded")) .body(containsString(buildLimitExceededMessage(2))) ); - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> when().get("/loop/3/resource").then().assertThat() .statusCode(200) .body(not(containsString(buildLimitExceededMessage(2)))) @@ -205,14 +206,14 @@ public void testRequestHopValidationWithLimitZero(TestContext context) { with().body("{\"request.hops.limit\":0}").put(ROUTING_CONFIG).then().assertThat().statusCode(200); // prepare test data - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> with().body("{\"someKey\":"+System.currentTimeMillis()+"}").put("/loop/4/resource").then().assertThat() .statusCode(500) .statusLine(containsString("Request hops limit exceeded")) .body(containsString(buildLimitExceededMessage(0))) ); - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> when().get("/loop/4/resource").then().assertThat() .statusCode(500) .statusLine(containsString("Request hops limit exceeded")) @@ -240,7 +241,7 @@ public void testRequestHopValidationManualHeaderValue(TestContext context) { TestUtils.putRoutingRules(rules); // configure request hops limit to 10 - com.jayway.awaitility.Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> + Awaitility.given().await().atMost(Duration.ONE_SECOND).until(() -> with().body("{\"request.hops.limit\":10}").put(ROUTING_CONFIG).then().assertThat().statusCode(200) ); validateRoutingConfig(true, 10); 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 new file mode 100644 index 000000000..801233ac4 --- /dev/null +++ b/gateleen-test/src/test/resources/org/swisspush/gateleen/hookjs/hook-js-ui-test.feature @@ -0,0 +1,11 @@ +Feature: hook-js UI Test + + Background: + Given Chrome has been started + And the hook-js UI is displayed + + Scenario: Place a sinlge hook and put single + When we click on the button "Place Single Hook" + Then we see the message "Installing listener 1" on position 1 + When we click on the button "PUT Single" + Then we see the message "Listener 1 received:" on position 2