summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2016-12-02 16:17:15 +0200
committerDenis <denis@vaadin.com>2016-12-02 17:17:15 +0300
commite746963efb1135e256da78cdd8cc24c88fdfd194 (patch)
tree5f86508bef50b4b7811ec8c7a597e737486449eb /uitest
parent54a6eef91cb2f0b8b7d65661162257711a2d6e2a (diff)
downloadvaadin-framework-e746963efb1135e256da78cdd8cc24c88fdfd194.tar.gz
vaadin-framework-e746963efb1135e256da78cdd8cc24c88fdfd194.zip
Introduce VaadinServiceInitListener (#18628) (#79)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/applicationservlet/ServiceInitListeners.java28
-rw-r--r--uitest/src/main/java/com/vaadin/tests/applicationservlet/TestingServiceInitListener.java56
-rw-r--r--uitest/src/main/resources/META-INF/services/com.vaadin.server.VaadinServiceInitListener1
-rw-r--r--uitest/src/test/java/com/vaadin/tests/applicationservlet/ServiceInitListenersTest.java39
4 files changed, 124 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/applicationservlet/ServiceInitListeners.java b/uitest/src/main/java/com/vaadin/tests/applicationservlet/ServiceInitListeners.java
new file mode 100644
index 0000000000..4ecb7cf0f0
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/applicationservlet/ServiceInitListeners.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.applicationservlet;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+
+public class ServiceInitListeners extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ log("Init count: " + TestingServiceInitListener.getInitCount());
+ log("Request count: " + TestingServiceInitListener.getRequestCount());
+ }
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/applicationservlet/TestingServiceInitListener.java b/uitest/src/main/java/com/vaadin/tests/applicationservlet/TestingServiceInitListener.java
new file mode 100644
index 0000000000..d0685ad975
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/applicationservlet/TestingServiceInitListener.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.applicationservlet;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.vaadin.server.RequestHandler;
+import com.vaadin.server.ServiceInitEvent;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinResponse;
+import com.vaadin.server.VaadinServiceInitListener;
+import com.vaadin.server.VaadinSession;
+
+public class TestingServiceInitListener implements VaadinServiceInitListener {
+
+ private static AtomicInteger initCount = new AtomicInteger();
+ private static AtomicInteger requestCount = new AtomicInteger();
+
+ @Override
+ public void serviceInit(ServiceInitEvent event) {
+ initCount.incrementAndGet();
+
+ event.addRequestHandler(new RequestHandler() {
+ @Override
+ public boolean handleRequest(VaadinSession session,
+ VaadinRequest request, VaadinResponse response)
+ throws IOException {
+ requestCount.incrementAndGet();
+ return false;
+ }
+ });
+ }
+
+ public static int getInitCount() {
+ return initCount.get();
+ }
+
+ public static int getRequestCount() {
+ return requestCount.get();
+ }
+
+}
diff --git a/uitest/src/main/resources/META-INF/services/com.vaadin.server.VaadinServiceInitListener b/uitest/src/main/resources/META-INF/services/com.vaadin.server.VaadinServiceInitListener
new file mode 100644
index 0000000000..ea3d467dab
--- /dev/null
+++ b/uitest/src/main/resources/META-INF/services/com.vaadin.server.VaadinServiceInitListener
@@ -0,0 +1 @@
+com.vaadin.tests.applicationservlet.TestingServiceInitListener
diff --git a/uitest/src/test/java/com/vaadin/tests/applicationservlet/ServiceInitListenersTest.java b/uitest/src/test/java/com/vaadin/tests/applicationservlet/ServiceInitListenersTest.java
new file mode 100644
index 0000000000..2c9403acdb
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/applicationservlet/ServiceInitListenersTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.applicationservlet;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ServiceInitListenersTest extends SingleBrowserTest {
+
+ @Test
+ public void testServiceInitListenerTriggered() {
+ openTestURL();
+
+ Assert.assertNotEquals(getLogRow(0), 0, extractCount(getLogRow(0)));
+ Assert.assertNotEquals(getLogRow(1), 0, extractCount(getLogRow(1)));
+ }
+
+ private int extractCount(String logRow) {
+ // Assuming row pattern is "label: 1"
+ String substring = logRow.replaceAll("[^:]*:\\s*", "");
+ return Integer.parseInt(substring);
+ }
+
+}