Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2016-02-04 14:37:43 +0000
committerFlorian Barbin2016-03-25 13:33:45 +0000
commitc04358746b1788e124b4ca99b900b95581ba4ab3 (patch)
tree93252979365cf34f73eb7da2474b9831d9a9f456
parent9ff9248fafe1605247cdf8ac467032aa68889988 (diff)
downloadorg.eclipse.sirius-c04358746b1788e124b4ca99b900b95581ba4ab3.tar.gz
org.eclipse.sirius-c04358746b1788e124b4ca99b900b95581ba4ab3.tar.xz
org.eclipse.sirius-c04358746b1788e124b4ca99b900b95581ba4ab3.zip
[485832] Adds Junit test
Bug: 485832 Change-Id: I65ed869dcf66afaf5568d70b92414e1fe02a05a3 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java88
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java3
2 files changed, 90 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java
new file mode 100644
index 0000000000..8cb256aea6
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/SecurityExceptionPopupTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2016 THALES GLOBAL SERVICES.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.swtbot;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition;
+
+/**
+ * This test checks that the securityException opens a popup only in the case of
+ * a nonempty message.
+ *
+ * @author Florian Barbin
+ *
+ */
+public class SecurityExceptionPopupTest extends AbstractSiriusSwtBotGefTestCase {
+
+ /**
+ * Logs a SecurityException with a message and makes sure the pop-up is
+ * opened.
+ */
+ public void testSecurityExceptionWithMessage() {
+ launchExceptionAndCheck(true);
+ }
+
+ /**
+ * Logs a SecurityException without message and checks that no pop-up is
+ * opened.
+ */
+ public void testSecurityExceptionWithoutMessage() {
+ launchExceptionAndCheck(false);
+ }
+
+ private void launchExceptionAndCheck(final boolean withMessage) {
+
+ // Step 1 - Log a security exception.
+ SecurityException exception = null;
+ if (withMessage) {
+ exception = new SecurityException("test");
+ } else {
+ exception = new SecurityException();
+ }
+
+ SiriusTestsPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, SiriusTestsPlugin.PLUGIN_ID, "exception occurs", exception));
+
+ // Step 2 - Check whether the dialog is opened
+ // or not (if there is no message in the exception, the dialog
+ // should not be opened).
+
+ Shell shell = null;
+ try {
+ WaitForObjectCondition<Shell> waitForShell = Conditions.waitForShell(WidgetMatcherFactory.<Shell> withText("Permission Issue"));
+ bot.waitUntilWidgetAppears(waitForShell);
+ shell = waitForShell.getAllMatches().get(0);
+ } catch (WidgetNotFoundException e) {
+ // We throw the exception only in the case where the
+ // dialog is expected (a SecurityException with a
+ // message).
+ if (withMessage) {
+ throw e;
+ }
+ }
+ errors.clear();
+ if (shell != null) {
+ // We close the shell and clear the error log.
+ bot.closeAllShells();
+ // If the exception was logged without message, we
+ // shouldn't have found a shell.
+ if (!withMessage) {
+ fail("There should not be a dialog with empty message");
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
index 05dd9ba71e..5fcf4c16a8 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES.
* 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
@@ -193,6 +193,7 @@ public class AllTestSuite extends TestCase {
suite.addTestSuite(LockedModelExplorerTest.class);
suite.addTestSuite(SnapAllShapesTest.class);
suite.addTestSuite(MoveEdgeGroupTest.class);
+ suite.addTestSuite(SecurityExceptionPopupTest.class);
}
/**

Back to the top