summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Drossel2009-01-20 09:37:45 (EST)
committerCarsten Drossel2009-01-20 09:37:45 (EST)
commitb0e77141f9db0b0d17d590aecd5aad06478ae438 (patch)
tree982ec060de848c671afa008c170883c001ca0f4e
parent4293f5a4a0957fe2d4d311db77e023954e09a0cc (diff)
downloadorg.eclipse.riena-b0e77141f9db0b0d17d590aecd5aad06478ae438.zip
org.eclipse.riena-b0e77141f9db0b0d17d590aecd5aad06478ae438.tar.gz
org.eclipse.riena-b0e77141f9db0b0d17d590aecd5aad06478ae438.tar.bz2
robustness: checking for inconsistent workarea definitions
-rw-r--r--org.eclipse.riena.navigation.ui.swt/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistry.java23
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistryTest.java122
2 files changed, 145 insertions, 0 deletions
diff --git a/org.eclipse.riena.navigation.ui.swt/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistry.java b/org.eclipse.riena.navigation.ui.swt/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistry.java
index bfead11..6c6b13c 100644
--- a/org.eclipse.riena.navigation.ui.swt/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistry.java
+++ b/org.eclipse.riena.navigation.ui.swt/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistry.java
@@ -18,6 +18,7 @@ import org.eclipse.riena.navigation.IModuleNodeExtension;
import org.eclipse.riena.navigation.INavigationAssemblyExtension;
import org.eclipse.riena.navigation.ISubApplicationNodeExtension;
import org.eclipse.riena.navigation.ISubModuleNodeExtension;
+import org.eclipse.riena.navigation.model.ExtensionPointFailure;
import org.eclipse.riena.ui.workarea.IWorkareaDefinition;
import org.eclipse.riena.ui.workarea.WorkareaDefinition;
import org.eclipse.riena.ui.workarea.spi.IWorkareaDefinitionRegistry;
@@ -35,6 +36,28 @@ public class SwtExtensionWorkareaDefinitionRegistry implements IWorkareaDefiniti
}
public IWorkareaDefinition register(Object id, IWorkareaDefinition definition) {
+
+ if (getDefinition(id) != null) {
+ IWorkareaDefinition existingDefinition = getDefinition(id);
+ if (!existingDefinition.getControllerClass().equals(definition.getControllerClass())) {
+ throw new ExtensionPointFailure(
+ "Inconsistent workarea definition: a definition for submodules with typeId=\"" + id //$NON-NLS-1$
+ + "\" already exists and it has a different controller (class " //$NON-NLS-1$
+ + existingDefinition.getControllerClass().getSimpleName() + " instead of " //$NON-NLS-1$
+ + definition.getControllerClass().getSimpleName() + ")."); //$NON-NLS-1$
+ }
+ if (!existingDefinition.getViewId().equals(definition.getViewId())) {
+ throw new ExtensionPointFailure(
+ "Inconsistent workarea definition: a definition for submodules with typeId=\"" + id //$NON-NLS-1$
+ + "\" already exists and it has a different view (" + existingDefinition.getViewId() //$NON-NLS-1$
+ + " instead of " + definition.getViewId() + ")."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (existingDefinition.isViewShared() != definition.isViewShared()) {
+ throw new ExtensionPointFailure(
+ "Inconsistent workarea definition: a definition for submodules with typeId=\"" + id //$NON-NLS-1$
+ + "\" already exists and it has a different shared value."); //$NON-NLS-1$
+ }
+ }
return workareas.put(id, definition);
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistryTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistryTest.java
new file mode 100644
index 0000000..e2e6e55
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/navigation/ui/swt/workarea/SwtExtensionWorkareaDefinitionRegistryTest.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG and others.
+ * 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.navigation.ui.swt.workarea;
+
+import org.eclipse.riena.navigation.model.ExtensionPointFailure;
+import org.eclipse.riena.navigation.ui.controllers.SubModuleController;
+import org.eclipse.riena.tests.RienaTestCase;
+import org.eclipse.riena.tests.collect.NonUITestCase;
+import org.eclipse.riena.ui.workarea.IWorkareaDefinition;
+import org.eclipse.riena.ui.workarea.WorkareaDefinition;
+
+/**
+ * Tests for the SwtExtensionWorkareaDefinitionRegistry
+ */
+@NonUITestCase
+public class SwtExtensionWorkareaDefinitionRegistryTest extends RienaTestCase {
+
+ private static final String TEST_TYPE_ID = "TestTypeId";
+ private static final String OTHER_TEST_TYPE_ID = "OtherTestTypeId";
+ private static final boolean TEST_IS_VIEW_SHARED = true;
+ private static final String TEST_VIEW_ID = "TestViewId";
+ private static final boolean OTHER_TEST_IS_VIEW_SHARED = false;
+ private static final String OTHER_TEST_VIEW_ID = "OtherTestViewId";
+
+ @SuppressWarnings("restriction")
+ private SwtExtensionWorkareaDefinitionRegistry workareaDefinitionRegistry;
+ private IWorkareaDefinition workareaDefinition;
+
+ @SuppressWarnings("restriction")
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ workareaDefinitionRegistry = new SwtExtensionWorkareaDefinitionRegistry();
+ workareaDefinition = new WorkareaDefinition(TestSubModuleController.class, TEST_VIEW_ID, TEST_IS_VIEW_SHARED);
+ }
+
+ @SuppressWarnings("restriction")
+ public void testRegisterDefinition() throws Exception {
+
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, workareaDefinition);
+
+ assertSame(workareaDefinition, workareaDefinitionRegistry.getDefinition(TEST_TYPE_ID));
+ }
+
+ @SuppressWarnings("restriction")
+ public void testRegisterSameDefinitionDifferentTypeId() throws Exception {
+
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, workareaDefinition);
+
+ IWorkareaDefinition otherWorkareaDefinition = new WorkareaDefinition(TestSubModuleController.class,
+ TEST_VIEW_ID, TEST_IS_VIEW_SHARED);
+ workareaDefinitionRegistry.register(OTHER_TEST_TYPE_ID, otherWorkareaDefinition);
+
+ assertSame(workareaDefinition, workareaDefinitionRegistry.getDefinition(TEST_TYPE_ID));
+ assertSame(otherWorkareaDefinition, workareaDefinitionRegistry.getDefinition(OTHER_TEST_TYPE_ID));
+ }
+
+ @SuppressWarnings("restriction")
+ public void testRegisterSameDefinitionSameTypeId() throws Exception {
+
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, workareaDefinition);
+
+ IWorkareaDefinition otherWorkareaDefinition = new WorkareaDefinition(TestSubModuleController.class,
+ TEST_VIEW_ID, TEST_IS_VIEW_SHARED);
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, otherWorkareaDefinition);
+
+ assertSame(otherWorkareaDefinition, workareaDefinitionRegistry.getDefinition(TEST_TYPE_ID));
+ assertNotSame(workareaDefinition, workareaDefinitionRegistry.getDefinition(TEST_TYPE_ID));
+ }
+
+ @SuppressWarnings("restriction")
+ public void testRegisterDifferentDefinitionSameTypeId() throws Exception {
+
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, workareaDefinition);
+
+ IWorkareaDefinition otherWorkareaDefinition = null;
+ try {
+ otherWorkareaDefinition = new WorkareaDefinition(OtherTestSubModuleController.class, TEST_VIEW_ID,
+ TEST_IS_VIEW_SHARED);
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, otherWorkareaDefinition);
+ fail("ExtensionPointFailure expected");
+ } catch (ExtensionPointFailure expected) {
+ ok("ExtensionPointFailure expected");
+ }
+
+ try {
+ otherWorkareaDefinition = new WorkareaDefinition(TestSubModuleController.class, OTHER_TEST_VIEW_ID,
+ TEST_IS_VIEW_SHARED);
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, otherWorkareaDefinition);
+ fail("ExtensionPointFailure expected");
+ } catch (ExtensionPointFailure expected) {
+ ok("ExtensionPointFailure expected");
+ }
+
+ try {
+ otherWorkareaDefinition = new WorkareaDefinition(TestSubModuleController.class, TEST_VIEW_ID,
+ OTHER_TEST_IS_VIEW_SHARED);
+ workareaDefinitionRegistry.register(TEST_TYPE_ID, otherWorkareaDefinition);
+ fail("ExtensionPointFailure expected");
+ } catch (ExtensionPointFailure expected) {
+ ok("ExtensionPointFailure expected");
+ }
+ }
+
+ private static class TestSubModuleController extends SubModuleController {
+
+ }
+
+ private static class OtherTestSubModuleController extends SubModuleController {
+
+ }
+
+}