Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremie Bresson2013-04-25 09:17:14 +0000
committerJeremie Bresson2013-04-25 09:18:13 +0000
commitdf88f7f69b6f65f60ef8eada6073bed649bd3be3 (patch)
tree56129f83d7fe38601008e1d5c70dd6acc5384b86
parentf0a7bca6f778c41c84f8e7e8faabc31c27aead70 (diff)
downloadorg.eclipse.scout.rt-df88f7f69b6f65f60ef8eada6073bed649bd3be3.tar.gz
org.eclipse.scout.rt-df88f7f69b6f65f60ef8eada6073bed649bd3be3.tar.xz
org.eclipse.scout.rt-df88f7f69b6f65f60ef8eada6073bed649bd3be3.zip
bug 402301: Migration: UI Independent tests
Add tests in: * org.eclipse.scout.rt.testing.client.test * org.eclipse.scout.rt.testing.server.test https://bugs.eclipse.org/bugs/show_bug.cgi?id=402301 Change-Id: Iacee6ef9bb76a11d6ea34f777628a3fd9c5eeea0
-rw-r--r--org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerAdditionalLoginTest.java147
-rw-r--r--org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerLoginTest.java114
-rw-r--r--org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/fixture/LoginTestSessionProvider.java63
-rw-r--r--org.eclipse.scout.rt.testing.server.test/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.scout.rt.testing.server.test/src/org/eclipse/scout/rt/testing/server/runner/ScoutServerTestRunnerTransactionBehaviorTest.java168
5 files changed, 494 insertions, 1 deletions
diff --git a/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerAdditionalLoginTest.java b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerAdditionalLoginTest.java
new file mode 100644
index 0000000000..09707fc0f5
--- /dev/null
+++ b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerAdditionalLoginTest.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BSI Business Systems Integration AG.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BSI Business Systems Integration AG - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.scout.testing.client.runner;
+
+import java.util.Collections;
+
+import org.eclipse.scout.rt.client.IClientSession;
+import org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession;
+import org.eclipse.scout.testing.client.runner.ScoutClientTestRunner.ClientTest;
+import org.eclipse.scout.testing.client.runner.fixture.LoginTestSessionProvider;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * JUnit test for {@link ScoutClientTestRunner} with additional login.
+ */
+@RunWith(ScoutClientTestRunner.class)
+@ClientTest(runAs = "test", sessionProvider = LoginTestSessionProvider.class, forceNewSession = true)
+public class ScoutClientTestRunnerAdditionalLoginTest {
+
+ private static IClientSession s_beforeClassClientSession;
+ private static TestEnvironmentClientSession s_beforeClientSession;
+ private static TestEnvironmentClientSession s_afterClientSession;
+
+ @BeforeClass
+ public static void beforeClass1() throws Exception {
+ checkBeforeClass();
+ }
+
+ @BeforeClass
+ public static void beforeClass2() throws Exception {
+ checkBeforeClass();
+ }
+
+ @AfterClass
+ public static void afterClass1() throws Exception {
+ checkAfterClass();
+ }
+
+ @AfterClass
+ public static void afterClass2() throws Exception {
+ checkAfterClass();
+ }
+
+ @Before
+ public void before1() throws Exception {
+ checkBefore();
+ }
+
+ @Before
+ public void before2() throws Exception {
+ checkBefore();
+ }
+
+ @After
+ public void after1() throws Exception {
+ checkAfter();
+ }
+
+ @After
+ public void after2() throws Exception {
+ checkAfter();
+ }
+
+ @Test
+ @ClientTest(runAs = "otherUser", sessionProvider = LoginTestSessionProvider.class)
+ public void testWithAdditionalLogin1() throws Exception {
+ checkTest();
+ }
+
+ @Test
+ @ClientTest(runAs = "thirdUser", sessionProvider = LoginTestSessionProvider.class)
+ public void testWithAdditionalLogin2() throws Exception {
+ checkTest();
+ }
+
+ private static void checkBeforeClass() {
+ Assert.assertNotNull(TestEnvironmentClientSession.get());
+ if (s_beforeClassClientSession == null) {
+ Assert.assertSame(LoginTestSessionProvider.getCurrentSession(), TestEnvironmentClientSession.get());
+ Assert.assertEquals(Collections.singletonList("test"), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.singletonList("test"), LoginTestSessionProvider.getAfterStartRunAs());
+ s_beforeClassClientSession = TestEnvironmentClientSession.get();
+ LoginTestSessionProvider.clearProtocol();
+ }
+ else {
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ }
+ }
+
+ private static void checkAfterClass() {
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ }
+
+ private void checkBefore() {
+ Assert.assertNotNull(TestEnvironmentClientSession.get());
+ if (s_beforeClientSession == null) {
+ Assert.assertSame(LoginTestSessionProvider.getCurrentSession(), TestEnvironmentClientSession.get());
+ Assert.assertEquals(1, LoginTestSessionProvider.getBeforeStartRunAs().size());
+ Assert.assertEquals(1, LoginTestSessionProvider.getAfterStartRunAs().size());
+ Assert.assertTrue("otherUser".equals(LoginTestSessionProvider.getBeforeStartRunAs().get(0)) || "thirdUser".equals(LoginTestSessionProvider.getBeforeStartRunAs().get(0)));
+ Assert.assertTrue("otherUser".equals(LoginTestSessionProvider.getAfterStartRunAs().get(0)) || "thirdUser".equals(LoginTestSessionProvider.getAfterStartRunAs().get(0)));
+ LoginTestSessionProvider.clearProtocol();
+ }
+ else {
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ Assert.assertSame(s_beforeClientSession, TestEnvironmentClientSession.get());
+ }
+ s_beforeClientSession = TestEnvironmentClientSession.get();
+ }
+
+ private void checkAfter() {
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ if (s_beforeClientSession != null) {
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ }
+ }
+
+ private void checkTest() {
+ try {
+ Assert.assertEquals(s_beforeClientSession, TestEnvironmentClientSession.get());
+ }
+ finally {
+ s_afterClientSession = s_beforeClientSession;
+ s_beforeClientSession = null;
+ }
+ }
+}
diff --git a/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerLoginTest.java b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerLoginTest.java
new file mode 100644
index 0000000000..f2401d9326
--- /dev/null
+++ b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/ScoutClientTestRunnerLoginTest.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BSI Business Systems Integration AG.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BSI Business Systems Integration AG - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.scout.testing.client.runner;
+
+import java.util.Collections;
+
+import org.eclipse.scout.rt.client.IClientSession;
+import org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession;
+import org.eclipse.scout.testing.client.runner.ScoutClientTestRunner.ClientTest;
+import org.eclipse.scout.testing.client.runner.fixture.LoginTestSessionProvider;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * JUnit test for {@link ScoutClientTestRunner} with login.
+ */
+@RunWith(ScoutClientTestRunner.class)
+@ClientTest(runAs = "test", sessionProvider = LoginTestSessionProvider.class, forceNewSession = true)
+public class ScoutClientTestRunnerLoginTest {
+
+ private static IClientSession s_beforeClassClientSession;
+
+ @BeforeClass
+ public static void beforeClass1() throws Exception {
+ checkBeforeClass();
+ }
+
+ @BeforeClass
+ public static void beforeClass2() throws Exception {
+ checkBeforeClass();
+ }
+
+ @AfterClass
+ public static void afterClass1() throws Exception {
+ checkAfterClass();
+ }
+
+ @AfterClass
+ public static void afterClass2() throws Exception {
+ checkAfterClass();
+ }
+
+ @Before
+ public void before1() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ @Before
+ public void before2() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ @After
+ public void after1() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ @After
+ public void after2() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ @Test
+ public void testWithAdditionalLogin1() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ @Test
+ public void testWithAdditionalLogin2() throws Exception {
+ checkBeforeAfterAndTest();
+ }
+
+ private static void checkBeforeClass() {
+ Assert.assertNotNull(TestEnvironmentClientSession.get());
+ if (s_beforeClassClientSession == null) {
+ Assert.assertSame(LoginTestSessionProvider.getCurrentSession(), TestEnvironmentClientSession.get());
+ Assert.assertEquals(Collections.singletonList("test"), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.singletonList("test"), LoginTestSessionProvider.getAfterStartRunAs());
+ s_beforeClassClientSession = TestEnvironmentClientSession.get();
+ LoginTestSessionProvider.clearProtocol();
+ }
+ else {
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ }
+ }
+
+ private static void checkAfterClass() {
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ }
+
+ private void checkBeforeAfterAndTest() {
+ Assert.assertNotNull(TestEnvironmentClientSession.get());
+ Assert.assertSame(s_beforeClassClientSession, TestEnvironmentClientSession.get());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getBeforeStartRunAs());
+ Assert.assertEquals(Collections.emptyList(), LoginTestSessionProvider.getAfterStartRunAs());
+ }
+}
diff --git a/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/fixture/LoginTestSessionProvider.java b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/fixture/LoginTestSessionProvider.java
new file mode 100644
index 0000000000..c2d8c34764
--- /dev/null
+++ b/org.eclipse.scout.rt.testing.client.test/src/org/eclipse/scout/testing/client/runner/fixture/LoginTestSessionProvider.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BSI Business Systems Integration AG.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BSI Business Systems Integration AG - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.scout.testing.client.runner.fixture;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.scout.rt.client.IClientSession;
+import org.eclipse.scout.testing.client.DefaultTestClientSessionProvider;
+
+public class LoginTestSessionProvider extends DefaultTestClientSessionProvider {
+
+ private static IClientSession s_currentSession;
+ private static List<String> s_beforeStartRunAs;
+ private static List<String> s_afterStartRunAs;
+
+ public LoginTestSessionProvider() {
+ clearProtocol();
+ }
+
+ @Override
+ public <T extends IClientSession> T getOrCreateClientSession(Class<T> clazz, String runAs, boolean createNew) {
+ T clientSession = super.getOrCreateClientSession(clazz, runAs, createNew);
+ s_currentSession = clientSession;
+ return clientSession;
+ }
+
+ @Override
+ protected void beforeStartSession(IClientSession clientSession, String runAs) {
+ s_beforeStartRunAs.add(runAs);
+ }
+
+ @Override
+ protected void afterStartSession(IClientSession clientSession, String runAs) {
+ s_afterStartRunAs.add(runAs);
+ }
+
+ public static void clearProtocol() {
+ s_beforeStartRunAs = new ArrayList<String>();
+ s_afterStartRunAs = new ArrayList<String>();
+ s_currentSession = null;
+ }
+
+ public static IClientSession getCurrentSession() {
+ return s_currentSession;
+ }
+
+ public static List<String> getBeforeStartRunAs() {
+ return s_beforeStartRunAs;
+ }
+
+ public static List<String> getAfterStartRunAs() {
+ return s_afterStartRunAs;
+ }
+}
diff --git a/org.eclipse.scout.rt.testing.server.test/META-INF/MANIFEST.MF b/org.eclipse.scout.rt.testing.server.test/META-INF/MANIFEST.MF
index c284722e86..f27a47618b 100644
--- a/org.eclipse.scout.rt.testing.server.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.scout.rt.testing.server.test/META-INF/MANIFEST.MF
@@ -8,5 +8,6 @@ Fragment-Host: org.eclipse.scout.rt.testing.server;bundle-version="3.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.hamcrest.core;version="[1.3.0,2.0.0)",
org.junit;version="[4.9.0,5.0.0)",
- org.junit.runner;version="[4.9.0,5.0.0)"
+ org.junit.runner;version="[4.9.0,5.0.0)",
+ org.junit.runners.model;version="[4.9.0,5.0.0)"
Require-Bundle: org.eclipse.scout.rt.server.testenvironment;bundle-version="[3.9.0,3.10.0)"
diff --git a/org.eclipse.scout.rt.testing.server.test/src/org/eclipse/scout/rt/testing/server/runner/ScoutServerTestRunnerTransactionBehaviorTest.java b/org.eclipse.scout.rt.testing.server.test/src/org/eclipse/scout/rt/testing/server/runner/ScoutServerTestRunnerTransactionBehaviorTest.java
new file mode 100644
index 0000000000..676d2c7ca8
--- /dev/null
+++ b/org.eclipse.scout.rt.testing.server.test/src/org/eclipse/scout/rt/testing/server/runner/ScoutServerTestRunnerTransactionBehaviorTest.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2013 BSI Business Systems Integration AG.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BSI Business Systems Integration AG - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.scout.rt.testing.server.runner;
+
+import org.eclipse.scout.rt.server.ThreadContext;
+import org.eclipse.scout.rt.server.testenvironment.TestEnvironmentServerSession;
+import org.eclipse.scout.rt.server.transaction.ITransaction;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * This test verifies the transaction behavior of Scout server tests.
+ * <ul>
+ * <li>All methods annotated with {@link BeforeClass} are executed in the same Scout transaction</li>
+ * <li>All methods annotated with {@link Before} or {@link After} are executed in the same Scout transaction as the test
+ * method itself (i.e. the one annotated with {@link Test}).</li>
+ * <li>All methods annotated with {@link AfterClass} are executed in the same Scout transaction</li>
+ * </ul>
+ */
+@RunWith(ScoutServerTestRunner.class)
+public class ScoutServerTestRunnerTransactionBehaviorTest {
+
+ // before and after class transactions
+ private static ITransaction s_beforeClassTransaction;
+ private static ITransaction s_afterClassTransaction;
+
+ // before and after test transactions. The content is switched in method
+ // checkTestTransactionBehavior.
+ private static ITransaction s_thisTestBeforeTransaction;
+ private static ITransaction s_thisTestAfterTransaction;
+
+ // the transaction the other test is compared to
+ private static ITransaction s_otherTestTransaction;
+
+ @BeforeClass
+ public static void beforeClass1() throws Exception {
+ checkBeforeClassTransactionBehavior();
+ }
+
+ @BeforeClass
+ public static void beforeClass2() throws Exception {
+ checkBeforeClassTransactionBehavior();
+ }
+
+ @AfterClass
+ public static void afterClass1() throws Exception {
+ checkAfterClassTransactionBehavior();
+ }
+
+ @AfterClass
+ public static void afterClass2() throws Exception {
+ checkAfterClassTransactionBehavior();
+ }
+
+ @Before
+ public void before1() throws Exception {
+ checkBeforeTransactionBehavior();
+ }
+
+ @Before
+ public void before2() throws Exception {
+ checkBeforeTransactionBehavior();
+ }
+
+ @After
+ public void after1() throws Exception {
+ checkAfterTransactionBehavior();
+ }
+
+ @After
+ public void after2() throws Exception {
+ checkAfterTransactionBehavior();
+ }
+
+ @Test
+ public void test1() {
+ checkTestTransactionBehavior();
+ }
+
+ @Test
+ public void test2() {
+ checkTestTransactionBehavior();
+ }
+
+ /**
+ * All methods annotated with @BeforeClass are expected to be executed in
+ * the same Scout transaction.
+ */
+ private static void checkBeforeClassTransactionBehavior() {
+ Assert.assertNotNull(TestEnvironmentServerSession.get());
+ Assert.assertNotNull(ThreadContext.getTransaction());
+ Assert.assertTrue(s_beforeClassTransaction == null
+ || s_beforeClassTransaction == ThreadContext.getTransaction());
+ s_beforeClassTransaction = ThreadContext.getTransaction();
+ }
+
+ /**
+ * All methods annotated with @BeforeClass are expected to be executed in
+ * the same Scout transaction.
+ */
+ private static void checkAfterClassTransactionBehavior() {
+ Assert.assertNotNull(TestEnvironmentServerSession.get());
+ Assert.assertNotNull(ThreadContext.getTransaction());
+ Assert.assertNotSame(s_beforeClassTransaction,
+ ThreadContext.getTransaction());
+ Assert.assertTrue(s_afterClassTransaction == null
+ || s_afterClassTransaction == ThreadContext.getTransaction());
+ s_afterClassTransaction = ThreadContext.getTransaction();
+ }
+
+ /**
+ * All methods annotated with @Before are expected to be executed in the
+ * same Scout transaction.
+ */
+ private static void checkBeforeTransactionBehavior() {
+ Assert.assertNotNull(TestEnvironmentServerSession.get());
+ Assert.assertNotNull(ThreadContext.getTransaction());
+ Assert.assertNotSame(s_beforeClassTransaction,
+ ThreadContext.getTransaction());
+ Assert.assertTrue(s_thisTestBeforeTransaction == null
+ || s_thisTestBeforeTransaction == ThreadContext
+ .getTransaction());
+ Assert.assertTrue(s_otherTestTransaction == null
+ || s_otherTestTransaction != ThreadContext.getTransaction());
+ s_thisTestBeforeTransaction = ThreadContext.getTransaction();
+ }
+
+ /**
+ * All methods annotated with @After are expected to be executed in the same
+ * Scout transaction.
+ */
+ private static void checkAfterTransactionBehavior() {
+ Assert.assertNotNull(TestEnvironmentServerSession.get());
+ Assert.assertNotNull(ThreadContext.getTransaction());
+ Assert.assertNotSame(s_beforeClassTransaction,
+ ThreadContext.getTransaction());
+ Assert.assertSame(s_thisTestAfterTransaction,
+ ThreadContext.getTransaction());
+ }
+
+ /**
+ * Every test is expected to run in its own Scout transaction.
+ */
+ private void checkTestTransactionBehavior() {
+ Assert.assertNotNull(TestEnvironmentServerSession.get());
+ Assert.assertNotNull(ThreadContext.getTransaction());
+ Assert.assertNotSame(s_beforeClassTransaction,
+ ThreadContext.getTransaction());
+ Assert.assertTrue(s_otherTestTransaction == null
+ || s_otherTestTransaction != ThreadContext.getTransaction());
+ s_otherTestTransaction = ThreadContext.getTransaction();
+ s_thisTestAfterTransaction = s_thisTestBeforeTransaction;
+ s_thisTestBeforeTransaction = null;
+ }
+}

Back to the top