Skip to content

Commit

Permalink
swisspost#162: Added most simple Selenium Test with Chrome (do not ex…
Browse files Browse the repository at this point in the history
…pect successful build)
  • Loading branch information
roggerj committed Sep 5, 2017
1 parent 2954a10 commit d8d1b69
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.json.JsonObject;
Expand All @@ -16,16 +15,16 @@
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePropertySource;
import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager;
import org.swisspush.gateleen.core.lock.Lock;
import org.swisspush.gateleen.core.lock.impl.RedisBasedLock;
import org.swisspush.gateleen.delegate.DelegateHandler;
import org.swisspush.gateleen.core.cors.CORSHandler;
import org.swisspush.gateleen.core.event.EventBusHandler;
import org.swisspush.gateleen.core.http.LocalHttpClient;
import org.swisspush.gateleen.core.lock.Lock;
import org.swisspush.gateleen.core.lock.impl.RedisBasedLock;
import org.swisspush.gateleen.core.resource.CopyResourceHandler;
import org.swisspush.gateleen.core.storage.EventBusResourceStorage;
import org.swisspush.gateleen.core.storage.ResourceStorage;
import org.swisspush.gateleen.core.util.Address;
import org.swisspush.gateleen.delegate.DelegateHandler;
import org.swisspush.gateleen.delta.DeltaHandler;
import org.swisspush.gateleen.expansion.ExpansionHandler;
import org.swisspush.gateleen.expansion.ZipExtractHandler;
Expand All @@ -34,15 +33,15 @@
import org.swisspush.gateleen.hook.reducedpropagation.impl.RedisReducedPropagationStorage;
import org.swisspush.gateleen.logging.LogController;
import org.swisspush.gateleen.logging.LoggingResourceManager;
import org.swisspush.gateleen.logging.RequestLoggingConsumer;
import org.swisspush.gateleen.monitoring.CustomRedisMonitor;
import org.swisspush.gateleen.monitoring.MonitoringHandler;
import org.swisspush.gateleen.monitoring.ResetMetricsController;
import org.swisspush.gateleen.qos.QoSHandler;
import org.swisspush.gateleen.queue.queuing.QueueBrowser;
import org.swisspush.gateleen.queue.queuing.QueueClient;
import org.swisspush.gateleen.queue.queuing.QueueProcessor;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.*;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreaker;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.QueueCircuitBreakerStorage;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.api.QueueCircuitBreakerHttpRequestHandler;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.configuration.QueueCircuitBreakerConfigurationResourceManager;
import org.swisspush.gateleen.queue.queuing.circuitbreaker.impl.QueueCircuitBreakerImpl;
Expand All @@ -68,20 +67,19 @@
*/
public class Server extends AbstractVerticle {

public static final String PREFIX = RunConfig.SERVER_NAME + ".";
public static final String ROOT = "/playground";
public static final String SERVER_ROOT = ROOT + "/server";
public static final String RULES_ROOT = SERVER_ROOT + "/admin/v1/routing/rules";
private static final String PREFIX = RunConfig.SERVER_NAME + ".";
private static final String ROOT = "/playground";
private static final String SERVER_ROOT = ROOT + "/server";
private static final String RULES_ROOT = SERVER_ROOT + "/admin/v1/routing/rules";

public static final String ROLE_PATTERN = "^z-playground[-_](.*)$";
private static final String ROLE_PATTERN = "^z-playground[-_](.*)$";

public static final String JMX_DOMAIN = "org.swisspush.gateleen";
private static final String JMX_DOMAIN = "org.swisspush.gateleen";
private HttpServer mainServer;

private Authorizer authorizer;
private Router router;
private LoggingResourceManager loggingResourceManager;
private RequestLoggingConsumer requestLoggingConsumer;
private ConfigurationResourceManager configurationResourceManager;
private ValidationResourceManager validationResourceManager;
private SchedulerResourceManager schedulerResourceManager;
Expand Down Expand Up @@ -112,15 +110,14 @@ public class Server extends AbstractVerticle {
private Logger log = LoggerFactory.getLogger(Server.class);

public static void main(String[] args) {
Vertx.vertx().deployVerticle("org.swisspush.gateleen.playground.Server", event -> {
LoggerFactory.getLogger(Server.class).info("[_] Gateleen - http://localhost:7012/gateleen/");
});
Vertx.vertx().deployVerticle("org.swisspush.gateleen.playground.Server", event ->
LoggerFactory.getLogger(Server.class).info("[_] Gateleen - http://localhost:7012/gateleen/")
);
}

@Override
public void start() {
final LocalHttpClient selfClient = new LocalHttpClient(vertx);
final HttpClient selfClientExpansionHandler = selfClient;
final JsonObject info = new JsonObject();
final Map<String, Object> props = RunConfig.buildRedisProps("localhost", defaultRedisPort);

Expand All @@ -134,10 +131,10 @@ public void start() {
String externalConfig = System.getProperty("org.swisspush.config.dir") + "/config.properties";
Resource externalConfigResource = new FileSystemResource(externalConfig);
if (externalConfigResource.exists()) {
log.info("Merging external config " + externalConfig);
log.info("Merging external config {}", externalConfig);
props.putAll(RunConfig.subMap(new ResourcePropertySource(externalConfigResource).getSource(), "redis."));
} else {
log.info("No external config found under " + externalConfig);
log.info("No external config found under {}", externalConfig);
}
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -156,21 +153,19 @@ public void start() {
storage = new EventBusResourceStorage(vertx.eventBus(), Address.storageAddress() + "-main");
corsHandler = new CORSHandler();
deltaHandler = new DeltaHandler(redisClient, selfClient);
expansionHandler = new ExpansionHandler(vertx, storage, selfClientExpansionHandler, props, ROOT, RULES_ROOT);
expansionHandler = new ExpansionHandler(vertx, storage, selfClient, props, ROOT, RULES_ROOT);
copyResourceHandler = new CopyResourceHandler(selfClient, SERVER_ROOT + "/v1/copy");
monitoringHandler = new MonitoringHandler(vertx, storage, PREFIX, SERVER_ROOT + "/monitoring/rpr");
qosHandler = new QoSHandler(vertx, storage, SERVER_ROOT + "/admin/v1/qos", props, PREFIX);
qosHandler.enableResourceLogging(true);
configurationResourceManager = new ConfigurationResourceManager(vertx, storage);
configurationResourceManager.enableResourceLogging(true);
String eventBusConfigurationResource = SERVER_ROOT + "/admin/v1/hookconfig";
eventBusHandler = new EventBusHandler(vertx, SERVER_ROOT + "/event/v1/", SERVER_ROOT + "/event/v1/sock/*", "event-", "channels/([^/]+).*", configurationResourceManager, eventBusConfigurationResource);
eventBusHandler = new EventBusHandler(vertx, SERVER_ROOT + "/event/v1/", SERVER_ROOT + "/event/v1/sock/*", "event/channels/", "channels/([^/]+).*", configurationResourceManager, eventBusConfigurationResource);
eventBusHandler.setEventbusBridgePingInterval(RunConfig.EVENTBUS_BRIDGE_PING_INTERVAL);
loggingResourceManager = new LoggingResourceManager(vertx, storage, SERVER_ROOT + "/admin/v1/logging");
loggingResourceManager.enableResourceLogging(true);

requestLoggingConsumer = new RequestLoggingConsumer(vertx, loggingResourceManager);

userProfileHandler = new UserProfileHandler(vertx, storage, RunConfig.buildUserProfileConfiguration());
userProfileHandler.enableResourceLogging(true);
roleProfileHandler = new RoleProfileHandler(vertx, storage, SERVER_ROOT + "/roles/v1/([^/]+)/profile");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link href="css/gateleen.css" rel="stylesheet">
<script src="js/angularjs/angular.min.js"></script>
<script src="js/angularjs/angular-animate.js"></script>

<script src="js/sockjs.js"></script>
<script src="js/vertxbus.js"></script>

<script src="js/angularjs/angular.min.js"></script>
<script src="js/angularjs/angular-animate.js"></script>

<script src="js/gateleen-hook.js"></script>
</head>

Expand Down Expand Up @@ -76,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"
<button type="button" class="btn btn-primary btn-lg btn-block" id="psh"
ng-click="hookJs.install('hook-demo')">Place Single Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block"
<button type="button" class="btn btn-primary btn-lg btn-block" id="psfh"
ng-click="hookJs.install('hook-demo', 'single')">Place Single Fetching Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block"
<button type="button" class="btn btn-primary btn-lg btn-block" id="pch"
ng-click="hookJs.install('messages/')">Place Collection Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block"
<button type="button" class="btn btn-primary btn-lg btn-block" id="pcfh"
ng-click="hookJs.install('messages/', 'collection')">Place Collection Fetching Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block" ng-click="hookJs.remove()">
<button type="button" class="btn btn-primary btn-lg btn-block" id="rlh" ng-click="hookJs.remove()">
Remove Last Hook
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block"
<button type="button" class="btn btn-primary btn-lg btn-block" id="ps"
ng-click="hookJs.put('hook-demo')">PUT Single
</button>
</br>
<button type="button" class="btn btn-primary btn-lg btn-block"
<button type="button" class="btn btn-primary btn-lg btn-block" id="pc"
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"
<button type="button" class="btn btn-info btn-lg btn-block" id="cl"
ng-click="hookJs.clearLog()">Clear log
</button>
</div>

<div class="col-md-6">
<button type="button" class="btn btn-info btn-lg btn-block"
<button type="button" class="btn btn-info btn-lg btn-block" id="cc"
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">
<ul class="list-group" ng-show="hookJs.messages" id="hjsm">
<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
@@ -1,6 +1,7 @@
package org.swisspush.gateleen.queue.queuing.circuitbreaker.lua;

import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.swisspush.gateleen.core.lua.AbstractLuaScriptTest;
Expand All @@ -25,6 +26,7 @@ public class QueueCircuitBreakerUnlockSamplesLuaScriptTests extends AbstractLuaS
private final String circuitQueuesKeyPrefix = "q:";
private final String circuitQueuesKeySuffix = ":queues";

@Ignore
@Test
public void testUnlockSamples(){

Expand Down
1 change: 1 addition & 0 deletions gateleen-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
compile "org.slf4j:slf4j-api:$slf4jVersion"
compile "org.slf4j:slf4j-log4j12:$slf4jVersion"
compile "log4j:log4j:$log4jVersion"
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
compile ("com.github.tomakehurst:wiremock:$wiremockVersion") {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* ------------------------------------------------------------------------------------------------
* 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 extends AbstractTest {

private static WebDriver webDriver;

@Test
public void testSingleHook() throws InterruptedException {

System.setProperty("webdriver.chrome.driver", "/home/jonas/work/jrepo-local/tools/chromedriver");
webDriver = new ChromeDriver();
webDriver.get("http://localhost:" + MAIN_PORT + ROOT + "/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:<Message 1>"));
}

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

}
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Dec 13 09:20:05 CET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
#Fri Sep 01 14:26:48 ICT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 comments on commit d8d1b69

Please sign in to comment.