Skip to content

Commit

Permalink
swisspost#162: implemented as cucumber test
Browse files Browse the repository at this point in the history
  • Loading branch information
roggerj committed Sep 11, 2017
1 parent 90313a1 commit e66c245
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 82 deletions.
12 changes: 6 additions & 6 deletions gateleen-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 }
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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:<Message 1>" on position 2

0 comments on commit e66c245

Please sign in to comment.