Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Bégaudeau2016-03-31 08:02:46 -0400
committerStephane Begaudeau2016-04-07 08:12:24 -0400
commitf6f650553bee0656bd8d7b9dfe3b0816dbfeea94 (patch)
tree01b7aa39851ba7694a037168803f40229c5fa0df /tests/org.eclipse.eef.tests/src
parentf9e41ebf561e225e05ea3d5e9afab6721606655c (diff)
downloadorg.eclipse.eef-f6f650553bee0656bd8d7b9dfe3b0816dbfeea94.tar.gz
org.eclipse.eef-f6f650553bee0656bd8d7b9dfe3b0816dbfeea94.tar.xz
org.eclipse.eef-f6f650553bee0656bd8d7b9dfe3b0816dbfeea94.zip
Add new unit tests
Change-Id: I74cc247e79ddc26499bac925bd3bb7cefe385c7a Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Diffstat (limited to 'tests/org.eclipse.eef.tests/src')
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java11
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/EEFDataTests.java81
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java147
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFButtonControllerTests.java67
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFCheckboxControllerTests.java66
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFLabelControllerTests.java66
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFRadioControllerTests.java66
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java66
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java125
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java71
10 files changed, 646 insertions, 120 deletions
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
index af55a2f98..951a0052f 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 Obeo.
+ * Copyright (c) 2015, 2016 Obeo.
* 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
@@ -10,7 +10,13 @@
*******************************************************************************/
package org.eclipse.eef.tests.internal;
+import org.eclipse.eef.tests.internal.controllers.EEFButtonControllerTests;
+import org.eclipse.eef.tests.internal.controllers.EEFCheckboxControllerTests;
+import org.eclipse.eef.tests.internal.controllers.EEFLabelControllerTests;
+import org.eclipse.eef.tests.internal.controllers.EEFRadioControllerTests;
+import org.eclipse.eef.tests.internal.controllers.EEFSelectControllerTests;
import org.eclipse.eef.tests.internal.controllers.EEFTextControllerTests;
+import org.eclipse.eef.tests.internal.core.EEFDomainClassTesterTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -21,7 +27,8 @@ import org.junit.runners.Suite.SuiteClasses;
* @author sbegaudeau
*/
@RunWith(Suite.class)
-@SuiteClasses({ EEFDataTests.class, EEFTextControllerTests.class })
+@SuiteClasses({ EEFDataTests.class, EEFTextControllerTests.class, EEFLabelControllerTests.class, EEFButtonControllerTests.class,
+ EEFCheckboxControllerTests.class, EEFRadioControllerTests.class, EEFSelectControllerTests.class, EEFDomainClassTesterTests.class })
public final class AllTests {
/**
* The constructor.
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/EEFDataTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/EEFDataTests.java
index 71feef781..f862e0d56 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/EEFDataTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/EEFDataTests.java
@@ -49,6 +49,81 @@ public class EEFDataTests {
public static final String EEFTEXTCONTROLLERTESTS_HELP = "/data/controllers/text/EEFTextControllerTests-Help.xmi"; //$NON-NLS-1$
/**
+ * Test model used to compute the help of a label widget.
+ */
+ public static final String EEFLABELCONTROLLERTESTS_HELP = "/data/controllers/label/EEFLabelControllerTests-Help.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the label of a label widget.
+ */
+ public static final String EEFLABELCONTROLLERTESTS_LABEL = "/data/controllers/label/EEFLabelControllerTests-Label.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the body of a label widget.
+ */
+ public static final String EEFLABELCONTROLLERTESTS_BODY = "/data/controllers/label/EEFLabelControllerTests-Body.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the label of a button widget.
+ */
+ public static final String EEFBUTTONCONTROLLERTESTS_LABEL = "/data/controllers/button/EEFButtonControllerTests-Label.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the help of a button widget.
+ */
+ public static final String EEFBUTTONCONTROLLERTESTS_HELP = "/data/controllers/button/EEFButtonControllerTests-Help.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the button label of a button widget.
+ */
+ public static final String EEFBUTTONCONTROLLERTESTS_BUTTONLABEL = "/data/controllers/button/EEFButtonControllerTests-ButtonLabel.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the label of a checkbox widget.
+ */
+ public static final String EEFCHECKBOXCONTROLLERTESTS_LABEL = "/data/controllers/checkbox/EEFCheckboxControllerTests-Label.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the help of a checkbox widget.
+ */
+ public static final String EEFCHECKBOXCONTROLLERTESTS_HELP = "/data/controllers/checkbox/EEFCheckboxControllerTests-Help.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the value of a checkbox widget.
+ */
+ public static final String EEFCHECKBOXCONTROLLERTESTS_VALUE = "/data/controllers/checkbox/EEFCheckboxControllerTests-Value.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the label of a radio widget.
+ */
+ public static final String EEFRADIOCONTROLLERTESTS_LABEL = "/data/controllers/radio/EEFRadioControllerTests-Label.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the help of a radio widget.
+ */
+ public static final String EEFRADIOCONTROLLERTESTS_HELP = "/data/controllers/radio/EEFRadioControllerTests-Help.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the value of a radio widget.
+ */
+ public static final String EEFRADIOCONTROLLERTESTS_VALUE = "/data/controllers/radio/EEFRadioControllerTests-Value.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the label of a select widget.
+ */
+ public static final String EEFSELECTCONTROLLERTESTS_LABEL = "/data/controllers/select/EEFSelectControllerTests-Label.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the help of a select widget.
+ */
+ public static final String EEFSELECTCONTROLLERTESTS_HELP = "/data/controllers/select/EEFSelectControllerTests-Help.xmi"; //$NON-NLS-1$
+
+ /**
+ * Test model used to compute the value of a select widget.
+ */
+ public static final String EEFSELECTCONTROLLERTESTS_VALUE = "/data/controllers/select/EEFSelectControllerTests-Value.xmi"; //$NON-NLS-1$
+
+ /**
* The current directory.
*/
public static final String CURRENTDIR = System.getProperty("user.dir"); //$NON-NLS-1$
@@ -56,7 +131,11 @@ public class EEFDataTests {
/**
* All the test models.
*/
- private static final String[] MODELS = new String[] { EEFTEXTCONTROLLERTESTS_LABEL, EEFTEXTCONTROLLERTESTS_VALUE, EEFTEXTCONTROLLERTESTS_HELP, };
+ private static final String[] MODELS = new String[] { EEFTEXTCONTROLLERTESTS_LABEL, EEFTEXTCONTROLLERTESTS_VALUE, EEFTEXTCONTROLLERTESTS_HELP,
+ EEFLABELCONTROLLERTESTS_LABEL, EEFLABELCONTROLLERTESTS_BODY, EEFLABELCONTROLLERTESTS_HELP, EEFBUTTONCONTROLLERTESTS_LABEL,
+ EEFBUTTONCONTROLLERTESTS_HELP, EEFBUTTONCONTROLLERTESTS_BUTTONLABEL, EEFCHECKBOXCONTROLLERTESTS_LABEL, EEFCHECKBOXCONTROLLERTESTS_HELP,
+ EEFCHECKBOXCONTROLLERTESTS_VALUE, EEFRADIOCONTROLLERTESTS_LABEL, EEFRADIOCONTROLLERTESTS_HELP, EEFRADIOCONTROLLERTESTS_VALUE,
+ EEFSELECTCONTROLLERTESTS_HELP, EEFSELECTCONTROLLERTESTS_LABEL, EEFSELECTCONTROLLERTESTS_VALUE, };
/**
* Loads the resource with the given URI in the given resource set.
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java
new file mode 100644
index 000000000..2cba5bd06
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/AbstractEEFControllerTests.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.eclipse.eef.EEFGroupDescription;
+import org.eclipse.eef.EEFPageDescription;
+import org.eclipse.eef.EEFViewDescription;
+import org.eclipse.eef.EEFWidgetDescription;
+import org.eclipse.eef.EefPackage;
+import org.eclipse.eef.core.api.EEFExpressionUtils;
+import org.eclipse.eef.core.api.controllers.IEEFWidgetController;
+import org.eclipse.eef.tests.internal.AQLInterpreter;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.eclipse.sirius.common.interpreter.api.IVariableManager;
+import org.eclipse.sirius.common.interpreter.api.VariableManagerFactory;
+import org.junit.Before;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Common superclass for all the tests of the controllers.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public abstract class AbstractEEFControllerTests {
+ /**
+ * The path of the dart.ecore file.
+ */
+ public static final String DART_ECORE = "/data/dart.ecore"; //$NON-NLS-1$
+
+ /**
+ * The editing domain.
+ */
+ protected TransactionalEditingDomainImpl editingDomain;
+
+ /**
+ * The resource set.
+ */
+ protected ResourceSetImpl resourceSet;
+
+ /**
+ * The interpreter.
+ */
+ protected IInterpreter interpreter;
+
+ @Before
+ public void setUp() {
+ this.resourceSet = new ResourceSetImpl();
+ this.resourceSet.getPackageRegistry().put(EefPackage.eNS_URI, EefPackage.eINSTANCE);
+ this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); //$NON-NLS-1$
+ this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); //$NON-NLS-1$
+
+ AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ this.editingDomain = new TransactionalEditingDomainImpl(adapterFactory, this.resourceSet);
+
+ this.interpreter = new AQLInterpreter();
+ }
+
+ protected EEFViewDescription view(String modelPath) {
+ Resource resource = EEFDataTests.loadResource(this.resourceSet, URI.createFileURI(EEFDataTests.CURRENTDIR + modelPath));
+ assertThat(resource, notNullValue());
+ EObject eObject = resource.getContents().get(0);
+ if (eObject instanceof EEFViewDescription) {
+ EEFViewDescription eefViewDescription = (EEFViewDescription) eObject;
+ return eefViewDescription;
+ }
+ throw new IllegalStateException("The root of the model is not a view description"); //$NON-NLS-1$
+ }
+
+ protected EEFPageDescription page(String modelPath, int pageIndex) {
+ return this.view(modelPath).getPages().get(pageIndex);
+ }
+
+ protected EEFGroupDescription group(EEFPageDescription eefPageDescription, int groupIndex) {
+ return eefPageDescription.getGroups().get(groupIndex);
+ }
+
+ protected <T extends EEFWidgetDescription> T widget(EEFGroupDescription eefGroupDescription, Class<T> clazz, int widgetIndex) {
+ List<T> list = eefGroupDescription.getContainer().getWidgets().stream().filter(w -> clazz.isAssignableFrom(w.getClass()))
+ .map(w -> clazz.cast(w)).collect(Collectors.toList());
+ return list.get(widgetIndex);
+ }
+
+ protected EPackage ePackage(String modelPath, int ePackageIndex) {
+ Resource resource = EEFDataTests.loadResource(this.resourceSet, URI.createFileURI(EEFDataTests.CURRENTDIR + modelPath));
+ assertThat(resource, notNullValue());
+ EObject eObject = resource.getContents().get(0);
+ if (eObject instanceof EPackage) {
+ return (EPackage) eObject;
+ }
+ throw new IllegalStateException("The root of the model is not an EPackage"); //$NON-NLS-1$
+ }
+
+ protected IVariableManager newVariableManager(EObject eObject) {
+ IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
+ variableManager.put(EEFExpressionUtils.SELF, eObject);
+ return variableManager;
+ }
+
+ protected void testLabel(IEEFWidgetController controller, String expectedLabel) {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ controller.onNewLabel(label -> {
+ assertThat(label, is(expectedLabel));
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+
+ protected void testHelp(IEEFWidgetController controller, String expectedHelp) {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ controller.onNewHelp(help -> {
+ assertThat(help, is(expectedHelp));
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFButtonControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFButtonControllerTests.java
new file mode 100644
index 000000000..b25e11725
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFButtonControllerTests.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.eef.EEFButtonDescription;
+import org.eclipse.eef.core.api.controllers.IEEFButtonController;
+import org.eclipse.eef.core.internal.controllers.EEFButtonController;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.ecore.EClassifier;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for the {@link IEEFButtonController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFButtonControllerTests extends AbstractEEFControllerTests {
+ /**
+ * The name of the Project EClass.
+ */
+ private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
+
+ private IEEFButtonController buttonController(String modelPath) {
+ EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
+ EEFButtonDescription description = widget(group(page(modelPath, 0), 0), EEFButtonDescription.class, 0);
+ return new EEFButtonController(description, newVariableManager(eClassifier), this.interpreter, this.editingDomain);
+ }
+
+ @Test
+ public void testLabel() {
+ testLabel(buttonController(EEFDataTests.EEFBUTTONCONTROLLERTESTS_LABEL), "Click:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(buttonController(EEFDataTests.EEFBUTTONCONTROLLERTESTS_HELP), "Click on the button"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testButtonLabel() {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ IEEFButtonController controller = this.buttonController(EEFDataTests.EEFBUTTONCONTROLLERTESTS_BUTTONLABEL);
+ controller.onNewButtonLabel(label -> {
+ assertThat(label, is("OK")); //$NON-NLS-1$
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFCheckboxControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFCheckboxControllerTests.java
new file mode 100644
index 000000000..f034e1dfa
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFCheckboxControllerTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.eef.EEFCheckboxDescription;
+import org.eclipse.eef.core.api.controllers.IEEFCheckboxController;
+import org.eclipse.eef.core.internal.controllers.EEFCheckboxController;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.ecore.EClassifier;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link IEEFCheckboxController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFCheckboxControllerTests extends AbstractEEFControllerTests {
+ /**
+ * The name of the Project EClass.
+ */
+ private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
+
+ private IEEFCheckboxController checkboxController(String modelPath) {
+ EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
+ EEFCheckboxDescription description = widget(group(page(modelPath, 0), 0), EEFCheckboxDescription.class, 0);
+ return new EEFCheckboxController(description, newVariableManager(eClassifier), this.interpreter, this.editingDomain);
+ }
+
+ @Test
+ public void testLabel() {
+ testLabel(checkboxController(EEFDataTests.EEFCHECKBOXCONTROLLERTESTS_LABEL), "Abstract:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(checkboxController(EEFDataTests.EEFCHECKBOXCONTROLLERTESTS_HELP), "Abstract Help"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testValue() {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ IEEFCheckboxController controller = this.checkboxController(EEFDataTests.EEFCHECKBOXCONTROLLERTESTS_VALUE);
+ controller.onNewValue(value -> {
+ assertThat(value, is(true));
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFLabelControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFLabelControllerTests.java
new file mode 100644
index 000000000..ccb475451
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFLabelControllerTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.eef.EEFLabelDescription;
+import org.eclipse.eef.core.api.controllers.IEEFLabelController;
+import org.eclipse.eef.core.internal.controllers.EEFLabelController;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.ecore.EClassifier;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for the {@link IEEFLabelController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFLabelControllerTests extends AbstractEEFControllerTests {
+ /**
+ * The name of the Project EClass.
+ */
+ private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
+
+ private IEEFLabelController labelController(String modelPath) {
+ EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
+ EEFLabelDescription description = widget(group(page(modelPath, 0), 0), EEFLabelDescription.class, 0);
+ return new EEFLabelController(description, newVariableManager(eClassifier), this.interpreter);
+ }
+
+ @Test
+ public void testLabel() {
+ testLabel(labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_LABEL), "Documentation:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_HELP), "Documentation Help"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testBody() {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ IEEFLabelController controller = this.labelController(EEFDataTests.EEFLABELCONTROLLERTESTS_BODY);
+ controller.onNewBody(label -> {
+ assertThat(label, is("This is the documentation of the project")); //$NON-NLS-1$
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFRadioControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFRadioControllerTests.java
new file mode 100644
index 000000000..7d17c5aa1
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFRadioControllerTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.eef.EEFRadioDescription;
+import org.eclipse.eef.core.api.controllers.IEEFRadioController;
+import org.eclipse.eef.core.internal.controllers.EEFRadioController;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.ecore.EClassifier;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link IEEFRadioController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFRadioControllerTests extends AbstractEEFControllerTests {
+ /**
+ * The name of the Project EClass.
+ */
+ private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
+
+ private IEEFRadioController radioController(String modelPath) {
+ EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
+ EEFRadioDescription description = widget(group(page(modelPath, 0), 0), EEFRadioDescription.class, 0);
+ return new EEFRadioController(description, newVariableManager(eClassifier), this.interpreter, this.editingDomain);
+ }
+
+ @Test
+ public void testLabel() {
+ testLabel(radioController(EEFDataTests.EEFRADIOCONTROLLERTESTS_LABEL), "Visibility:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(radioController(EEFDataTests.EEFRADIOCONTROLLERTESTS_HELP), "Visibility Help"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testValue() {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ IEEFRadioController controller = this.radioController(EEFDataTests.EEFRADIOCONTROLLERTESTS_VALUE);
+ controller.onNewValue(value -> {
+ assertThat(value, is("public")); //$NON-NLS-1$
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java
new file mode 100644
index 000000000..a9c09963c
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFSelectControllerTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.controllers;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.eef.EEFSelectDescription;
+import org.eclipse.eef.core.api.controllers.IEEFSelectController;
+import org.eclipse.eef.core.internal.controllers.EEFSelectController;
+import org.eclipse.eef.tests.internal.EEFDataTests;
+import org.eclipse.emf.ecore.EClassifier;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link IEEFSelectController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFSelectControllerTests extends AbstractEEFControllerTests {
+ /**
+ * The name of the Project EClass.
+ */
+ private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
+
+ private IEEFSelectController selectController(String modelPath) {
+ EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
+ EEFSelectDescription description = widget(group(page(modelPath, 0), 0), EEFSelectDescription.class, 0);
+ return new EEFSelectController(description, newVariableManager(eClassifier), this.interpreter, this.editingDomain);
+ }
+
+ @Test
+ public void testLabel() {
+ testLabel(selectController(EEFDataTests.EEFSELECTCONTROLLERTESTS_LABEL), "Visibility:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(selectController(EEFDataTests.EEFSELECTCONTROLLERTESTS_HELP), "Visibility Help"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testValue() {
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
+ IEEFSelectController controller = this.selectController(EEFDataTests.EEFSELECTCONTROLLERTESTS_VALUE);
+ controller.onNewValue(value -> {
+ assertThat(value, is("public")); //$NON-NLS-1$
+ atomicBoolean.set(true);
+ });
+ controller.refresh();
+ assertTrue(atomicBoolean.get());
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java
index c75467c60..0c032b046 100644
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java
@@ -10,41 +10,17 @@
*******************************************************************************/
package org.eclipse.eef.tests.internal.controllers;
-import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.stream.Collectors;
-import org.eclipse.eef.EEFGroupDescription;
-import org.eclipse.eef.EEFPageDescription;
import org.eclipse.eef.EEFTextDescription;
-import org.eclipse.eef.EEFViewDescription;
-import org.eclipse.eef.EEFWidgetDescription;
-import org.eclipse.eef.EefPackage;
-import org.eclipse.eef.core.api.EEFExpressionUtils;
import org.eclipse.eef.core.api.controllers.IEEFTextController;
import org.eclipse.eef.core.internal.controllers.EEFTextController;
-import org.eclipse.eef.tests.internal.AQLInterpreter;
import org.eclipse.eef.tests.internal.EEFDataTests;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
-import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
-import org.eclipse.sirius.common.interpreter.api.IInterpreter;
-import org.eclipse.sirius.common.interpreter.api.IVariableManager;
-import org.eclipse.sirius.common.interpreter.api.VariableManagerFactory;
-import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertTrue;
@@ -54,100 +30,27 @@ import static org.junit.Assert.assertTrue;
* @author sbegaudeau
*/
@SuppressWarnings({ "checkstyle:javadocmethod" })
-public class EEFTextControllerTests {
- /**
- * The path of the dart.ecore file.
- */
- private static final String DART_ECORE = "/data/dart.ecore"; //$NON-NLS-1$
+public class EEFTextControllerTests extends AbstractEEFControllerTests {
/**
* The name of the Project EClass.
*/
private static final String PROJECT_ECLASS_NAME = "Project"; //$NON-NLS-1$
- /**
- * The editing domain.
- */
- private TransactionalEditingDomainImpl editingDomain;
-
- /**
- * The resource set.
- */
- private ResourceSetImpl resourceSet;
-
- /**
- * The interpreter.
- */
- private IInterpreter interpreter;
-
- @Before
- public void setUp() {
- this.resourceSet = new ResourceSetImpl();
- this.resourceSet.getPackageRegistry().put(EefPackage.eNS_URI, EefPackage.eINSTANCE);
- this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); //$NON-NLS-1$
- this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); //$NON-NLS-1$
-
- AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
- this.editingDomain = new TransactionalEditingDomainImpl(adapterFactory, this.resourceSet);
-
- this.interpreter = new AQLInterpreter();
- }
-
- private EEFViewDescription view(String modelPath) {
- Resource resource = EEFDataTests.loadResource(this.resourceSet, URI.createFileURI(EEFDataTests.CURRENTDIR + modelPath));
- assertThat(resource, notNullValue());
- EObject eObject = resource.getContents().get(0);
- if (eObject instanceof EEFViewDescription) {
- EEFViewDescription eefViewDescription = (EEFViewDescription) eObject;
- return eefViewDescription;
- }
- throw new IllegalStateException("The root of the model is not a view description"); //$NON-NLS-1$
- }
-
- private EEFPageDescription page(String modelPath, int pageIndex) {
- return this.view(modelPath).getPages().get(pageIndex);
- }
-
- private EEFGroupDescription group(EEFPageDescription eefPageDescription, int groupIndex) {
- return eefPageDescription.getGroups().get(groupIndex);
- }
-
- private <T extends EEFWidgetDescription> T widget(EEFGroupDescription eefGroupDescription, Class<T> clazz, int widgetIndex) {
- List<T> list = eefGroupDescription.getContainer().getWidgets().stream().filter(w -> clazz.isAssignableFrom(w.getClass()))
- .map(w -> clazz.cast(w)).collect(Collectors.toList());
- return list.get(widgetIndex);
- }
-
- private EPackage ePackage(String modelPath, int ePackageIndex) {
- Resource resource = EEFDataTests.loadResource(this.resourceSet, URI.createFileURI(EEFDataTests.CURRENTDIR + modelPath));
- assertThat(resource, notNullValue());
- EObject eObject = resource.getContents().get(0);
- if (eObject instanceof EPackage) {
- return (EPackage) eObject;
- }
- throw new IllegalStateException("The root of the model is not an EPackage"); //$NON-NLS-1$
- }
-
private IEEFTextController textController(String modelPath) {
EClassifier eClassifier = this.ePackage(DART_ECORE, 0).getEClassifier(PROJECT_ECLASS_NAME);
-
- IVariableManager variableManager = new VariableManagerFactory().createVariableManager();
- variableManager.put(EEFExpressionUtils.SELF, eClassifier);
-
EEFTextDescription description = widget(group(page(modelPath, 0), 0), EEFTextDescription.class, 0);
- return new EEFTextController(description, variableManager, this.interpreter, this.editingDomain);
+ return new EEFTextController(description, newVariableManager(eClassifier), this.interpreter, this.editingDomain);
}
@Test
public void testLabel() {
- AtomicBoolean atomicBoolean = new AtomicBoolean(false);
- IEEFTextController controller = this.textController(EEFDataTests.EEFTEXTCONTROLLERTESTS_LABEL);
- controller.onNewLabel(label -> {
- assertThat(label, is("Project:")); //$NON-NLS-1$
- atomicBoolean.set(true);
- });
- controller.refresh();
- assertTrue(atomicBoolean.get());
+ testLabel(textController(EEFDataTests.EEFTEXTCONTROLLERTESTS_LABEL), "Project:"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testHelp() {
+ testHelp(textController(EEFDataTests.EEFTEXTCONTROLLERTESTS_HELP), "Project Help"); //$NON-NLS-1$
}
@Test
@@ -161,16 +64,4 @@ public class EEFTextControllerTests {
controller.refresh();
assertTrue(atomicBoolean.get());
}
-
- @Test
- public void testHelp() {
- AtomicBoolean atomicBoolean = new AtomicBoolean(false);
- IEEFTextController controller = this.textController(EEFDataTests.EEFTEXTCONTROLLERTESTS_HELP);
- controller.onNewHelp(help -> {
- assertThat(help, is("Project Help")); //$NON-NLS-1$
- atomicBoolean.set(true);
- });
- controller.refresh();
- assertTrue(atomicBoolean.get());
- }
}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java
new file mode 100644
index 000000000..252eb9004
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/core/EEFDomainClassTesterTests.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Obeo.
+ * 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.eef.tests.internal.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.eef.EefFactory;
+import org.eclipse.eef.EefPackage;
+import org.eclipse.eef.core.api.EEFDomainClassTester;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests of {@link EEFDomainClassTester}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFDomainClassTesterTests {
+
+ private void test(EPackage ePackage, EObject eObject, String domainClass) {
+ List<EPackage> ePackages = new ArrayList<>();
+ ePackages.add(ePackage);
+ assertTrue(new EEFDomainClassTester().eInstanceOf(ePackages, eObject, domainClass));
+ }
+
+ @Test
+ public void testDomainClass() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "eef.EEFButtonDescription"); //$NON-NLS-1$
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "eef::EEFButtonDescription"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testDomainClassWithoutPackageName() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "EEFButtonDescription"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testEObjectDomainClass() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "ecore.EObject"); //$NON-NLS-1$
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "ecore::EObject"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testEObjectDomainClassWithoutPackageName() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "EObject"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testSuperclassDomainClass() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "eef.EEFWidgetDescription"); //$NON-NLS-1$
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "eef::EEFWidgetDescription"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testSuperclassDomainClassWithoutPackageName() {
+ this.test(EefPackage.eINSTANCE, EefFactory.eINSTANCE.createEEFButtonDescription(), "EEFWidgetDescription"); //$NON-NLS-1$
+ }
+}

Back to the top