Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Bégaudeau2015-11-26 10:06:26 -0500
committerMelanie Bats2015-12-01 11:52:02 -0500
commit18bad80596e86e825aee7b6831710ece8adfce60 (patch)
tree3d00e11c41916eb6b464399891a2879fbba86d48 /tests/org.eclipse.eef.tests/src/org
parent90b2f509bdb2e2a792fec65621767ff77ebff303 (diff)
downloadorg.eclipse.eef-18bad80596e86e825aee7b6831710ece8adfce60.tar.gz
org.eclipse.eef-18bad80596e86e825aee7b6831710ece8adfce60.tar.xz
org.eclipse.eef-18bad80596e86e825aee7b6831710ece8adfce60.zip
Add basic tests for the EEFTextController
Change-Id: I3a9e4a7b8fa7d6a496c98e6b9c174654d969d4ce Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Diffstat (limited to 'tests/org.eclipse.eef.tests/src/org')
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/AllTests.java3
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/InitializationTests.java32
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java97
-rw-r--r--tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EvaluationResult.java76
4 files changed, 175 insertions, 33 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 9c36f282a..3f42caeff 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.eef.tests.internal;
+import org.eclipse.eef.tests.internal.controllers.EEFTextControllerTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -20,7 +21,7 @@ import org.junit.runners.Suite.SuiteClasses;
* @author sbegaudeau
*/
@RunWith(Suite.class)
-@SuiteClasses({ InitializationTests.class })
+@SuiteClasses({ EEFTextControllerTests.class })
public final class AllTests {
/**
* The constructor.
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/InitializationTests.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/InitializationTests.java
deleted file mode 100644
index ebf11d002..000000000
--- a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/InitializationTests.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2015 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;
-
-import org.eclipse.eef.EEFViewDescription;
-import org.eclipse.eef.EefFactory;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-
-/**
- * This class will be used to test the initialization of the controllers.
- *
- * @author sbegaudeau
- */
-@SuppressWarnings({ "checkstyle:javadocmethod" })
-public class InitializationTests {
- @Test
- public void testEmptyView() {
- EEFViewDescription eefViewDescription = EefFactory.eINSTANCE.createEEFViewDescription();
- // TODO Create a meaningful test :)
- assertNotNull(eefViewDescription);
- }
-}
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
new file mode 100644
index 000000000..d47e739b7
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EEFTextControllerTests.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.Map;
+
+import org.eclipse.eef.EEFTextDescription;
+import org.eclipse.eef.EefFactory;
+import org.eclipse.eef.core.api.EEFVariableManagerFactory;
+import org.eclipse.eef.core.api.IVariableManager;
+import org.eclipse.eef.core.api.controllers.EEFTextController;
+import org.eclipse.eef.core.internal.controllers.EEFTextControllerImpl;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.sirius.common.interpreter.api.IInterpreter;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+
+/**
+ * Unit tests for the {@link EEFTextController}.
+ *
+ * @author sbegaudeau
+ */
+@SuppressWarnings({ "checkstyle:javadocmethod" })
+public class EEFTextControllerTests {
+ /**
+ * The editing domain.
+ */
+ private TransactionalEditingDomainImpl editingDomain;
+
+ /**
+ * The description.
+ */
+ private EEFTextDescription description;
+
+ /**
+ * The variable manager.
+ */
+ private IVariableManager variableManager;
+
+ @Before
+ public void setUp() {
+ AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ this.editingDomain = new TransactionalEditingDomainImpl(adapterFactory);
+ this.variableManager = new EEFVariableManagerFactory().createVariableManager();
+
+ this.description = EefFactory.eINSTANCE.createEEFTextDescription();
+
+ this.description.setLabelExpression("aql:'General'"); //$NON-NLS-1$
+ this.description.setValueExpression("aql:self.name"); //$NON-NLS-1$
+ this.description.setEditExpression("aql.self.eSet('name', newValue)"); //$NON-NLS-1$
+ }
+
+ @Test
+ public void testUpdateValue() {
+ final String newValue = "newValue"; //$NON-NLS-1$
+
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ return new EvaluationResult(newValue);
+ };
+
+ EEFTextController controller = new EEFTextControllerImpl(description, variableManager, interpreter, editingDomain);
+ controller.onNewValue((text) -> {
+ assertThat(text, equalTo(newValue));
+ });
+
+ controller.refresh();
+ }
+
+ @Test
+ public void testUpdateLabel() {
+ final String newLabel = "Label"; //$NON-NLS-1$
+
+ IInterpreter interpreter = (Map<String, Object> variables, String expressionBody) -> {
+ return new EvaluationResult(newLabel);
+ };
+
+ EEFTextController controller = new EEFTextControllerImpl(description, variableManager, interpreter, editingDomain);
+ controller.onNewLabel((label) -> {
+ assertThat(label, equalTo(newLabel));
+ });
+
+ controller.refresh();
+ }
+}
diff --git a/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EvaluationResult.java b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EvaluationResult.java
new file mode 100644
index 000000000..167e08d6c
--- /dev/null
+++ b/tests/org.eclipse.eef.tests/src/org/eclipse/eef/tests/internal/controllers/EvaluationResult.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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 org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.sirius.common.interpreter.api.IEvaluationResult;
+
+/**
+ * The evaluation result.
+ *
+ * @author sbegaudeau
+ */
+public class EvaluationResult implements IEvaluationResult {
+
+ /**
+ * The value.
+ */
+ private Object value;
+
+ /**
+ * The diagnostic.
+ */
+ private Diagnostic diagnostic;
+
+ /**
+ * The constructor.
+ *
+ * @param value
+ * The value
+ */
+ public EvaluationResult(Object value) {
+ this(value, Diagnostic.OK_INSTANCE);
+ }
+
+ /**
+ * The constructor.
+ *
+ * @param value
+ * The value
+ * @param diagnostic
+ * The diagnostic
+ */
+ public EvaluationResult(Object value, Diagnostic diagnostic) {
+ this.value = value;
+ this.diagnostic = diagnostic;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.sirius.common.interpreter.api.IEvaluationResult#getValue()
+ */
+ @Override
+ public Object getValue() {
+ return this.value;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.sirius.common.interpreter.api.IEvaluationResult#getDiagnostic()
+ */
+ @Override
+ public Diagnostic getDiagnostic() {
+ return this.diagnostic;
+ }
+
+}

Back to the top