diff options
5 files changed, 180 insertions, 35 deletions
diff --git a/tests/org.eclipse.eef.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.eef.tests/META-INF/MANIFEST.MF index 8422d578c..c28bd8ed0 100644 --- a/tests/org.eclipse.eef.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.eef.tests/META-INF/MANIFEST.MF @@ -6,7 +6,10 @@ Bundle-Version: 2.0.0.qualifier Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Localization: plugin -Export-Package: org.eclipse.eef.tests.internal;version="2.0.0" +Export-Package: org.eclipse.eef.tests.internal;version="2.0.0";x-internal:=true, + org.eclipse.eef.tests.internal.controllers;version="2.0.0";x-internal:=true Require-Bundle: org.junit;bundle-version="[4.12.0,5.0.0)", org.eclipse.eef;bundle-version="[2.0.0,3.0.0)", - org.eclipse.eef.core;bundle-version="[2.0.0,3.0.0)" + org.eclipse.eef.core;bundle-version="[2.0.0,3.0.0)", + org.eclipse.emf.transaction;bundle-version="[1.9.0,2.0.0)", + org.eclipse.sirius.common.interpreter;bundle-version="[1.0.0,2.0.0)" 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; + } + +} |