From 42f0b44af4e8d8b4a953234913d514a03c4225bb Mon Sep 17 00:00:00 2001 From: Martin Fleck Date: Wed, 7 Dec 2016 17:18:51 +0100 Subject: [PATCH] [506928] ComparisonScopeEditorInput does not respect configuration Initialize comparison input with comparison configuration. Includes tests. Bug: 506928 Change-Id: I39c07e0093211170a81aba07fe082d0aafc74afa Also-by: Tobias Ortmayr Signed-off-by: Martin Fleck --- .../ui/tests/internal/editor/TestBug506928.java | 144 +++++++++++++++++++++ .../tests/internal/editor/data/_506928/left.nodes | 6 + .../internal/editor/data/_506928/origin.nodes | 5 + .../tests/internal/editor/data/_506928/right.nodes | 4 + .../compare/ide/ui/tests/suite/BugsTestSuite.java | 7 +- .../editor/ComparisonScopeEditorInput.java | 11 +- 6 files changed, 172 insertions(+), 5 deletions(-) create mode 100644 plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/TestBug506928.java create mode 100644 plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/left.nodes create mode 100644 plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/origin.nodes create mode 100644 plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/right.nodes diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/TestBug506928.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/TestBug506928.java new file mode 100644 index 000000000..9d8dd5fb5 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/TestBug506928.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2016 EclipseSource Services GmbH 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: + * Tobias Ortmayr - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.ide.ui.tests.internal.editor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.compare.EMFCompare; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain; +import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; +import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput; +import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeInput; +import org.eclipse.emf.compare.scope.DefaultComparisonScope; +import org.eclipse.emf.compare.scope.IComparisonScope; +import org.eclipse.emf.compare.tests.framework.AbstractInputData; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that the {@link ComparisonScopeEditorInput} is correctly initialized with the + * {@link EMFCompareConfiguration}. This test is related to the bug + * 506928 + * + * @author Tobias Ortmayr + */ +@SuppressWarnings("restriction") +public class TestBug506928 { + private Resource left, right, origin; + + private ICompareEditingDomain editingDomain; + + private ComposedAdapterFactory adapterFactory; + + private EMFCompare comparator; + + @Before + public void setUp() throws IOException { + Bug506928InputData inputData = new Bug506928InputData(); + left = inputData.getResource("left.nodes"); //$NON-NLS-1$ + right = inputData.getResource("right.nodes"); //$NON-NLS-1$ + origin = inputData.getResource("origin.nodes"); //$NON-NLS-1$ + editingDomain = EMFCompareEditingDomain.create(left, right, origin); + adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + comparator = EMFCompare.builder().build(); + } + + @SuppressWarnings({"boxing" }) + protected void testComparisonScopeEditorInput(boolean leftEditable, boolean rightEditable) { + // create configuration + EMFCompareConfiguration configuration = new EMFCompareConfiguration(new CompareConfiguration()); + configuration.setLeftEditable(leftEditable); + configuration.setRightEditable(rightEditable); + + // create comparison scope editor input based on configuration + IComparisonScope scope = new DefaultComparisonScope(left, right, origin); + ComparisonScopeEditorInput input = new ComparisonScopeEditorInput(configuration, editingDomain, + adapterFactory, comparator, scope); + + // no comparison result before opening the editor + assertEquals(input.getCompareResult(), null); + + // open editor to get comparison result + try { + input.run(new NullProgressMonitor()); + } catch (InvocationTargetException e) { + fail(e.getMessage()); + } catch (InterruptedException e) { + fail(e.getMessage()); + } + + // ensure correct result + assertTrue(input.getCompareResult() instanceof ComparisonScopeInput); + ComparisonScopeInput result = (ComparisonScopeInput)input.getCompareResult(); + + // assert compare configuration has not been changed + assertEquals(leftEditable, input.getCompareConfiguration().isLeftEditable()); + assertEquals(rightEditable, input.getCompareConfiguration().isRightEditable()); + + // assert result reflects the correct configuration + assertEquals(input.getCompareConfiguration().isLeftEditable(), result.isLeftEditable()); + assertEquals(input.getCompareConfiguration().isRightEditable(), result.isRightEditable()); + } + + /** + * Tests that the compare configuration is propagated correctly when both sides are not editable. + */ + @Test + public void testComparisionScopeEditorInput_BothNotEditable() { + testComparisonScopeEditorInput(false, false); + } + + /** + * Tests that the compare configuration is propagated correctly when only the left side is editable. + */ + @Test + public void testComparisionScopeEditorInput_LeftEditable() { + testComparisonScopeEditorInput(true, false); + } + + /** + * Tests that the compare configuration is propagated correctly when only the right side is editable. + */ + @Test + public void testComparisionScopeEditorInput_RightEditable() { + testComparisonScopeEditorInput(false, true); + } + + /** + * Tests that the compare configuration is propagated correctly when both sides are editable. + */ + @Test + public void testComparisionScopeEditorInput_BothEditable() { + testComparisonScopeEditorInput(true, true); + } + + public class Bug506928InputData extends AbstractInputData { + + private static final String PATH_PREFIX = "data/_506928/"; //$NON-NLS-1$ + + public Resource getResource(String resourceName) throws IOException { + StringBuilder resourceURL = new StringBuilder(PATH_PREFIX); + resourceURL.append(resourceName); + return loadFromClassLoader(resourceURL.toString()); + } + } + +} diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/left.nodes b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/left.nodes new file mode 100644 index 000000000..24d08b565 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/left.nodes @@ -0,0 +1,6 @@ + + + + + + diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/origin.nodes b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/origin.nodes new file mode 100644 index 000000000..bcf6f07b3 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/origin.nodes @@ -0,0 +1,5 @@ + + + + + diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/right.nodes b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/right.nodes new file mode 100644 index 000000000..5cdea6520 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/internal/editor/data/_506928/right.nodes @@ -0,0 +1,4 @@ + + + + diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/BugsTestSuite.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/BugsTestSuite.java index b758f335b..570146c95 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/BugsTestSuite.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/suite/BugsTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Obeo. + * Copyright (c) 2014, 2016 Obeo 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 @@ -7,9 +7,11 @@ * * Contributors: * Obeo - initial API and implementation + * Tobias Ortmayr - bug 506928 *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.tests.suite; +import org.eclipse.emf.compare.ide.ui.tests.internal.editor.TestBug506928; import org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions.TestBug434822; import org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions.TestBug434827; import org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions.TestBug434828; @@ -29,6 +31,7 @@ import org.junit.runners.Suite.SuiteClasses; */ @RunWith(Suite.class) @SuiteClasses({TestBug434827.class, TestBug434822.class, TestBug434828.class, TestBug434828_2.class, - TestBug459131.class, TestBug470503.class, TestBug475586.class, TestBug497566.class }) + TestBug459131.class, TestBug470503.class, TestBug475586.class, TestBug497566.class, + TestBug506928.class }) public class BugsTestSuite { } diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java index 72840c1ff..adddf04d3 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/editor/ComparisonScopeEditorInput.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Obeo. + * Copyright (c) 2012, 2016 Obeo 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 @@ -7,6 +7,7 @@ * * Contributors: * Obeo - initial API and implementation + * Tobias Ortmayr - bug 506928 *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.internal.editor; @@ -50,8 +51,12 @@ public class ComparisonScopeEditorInput extends AbstractEMFCompareEditorInput { @Override protected Object doPrepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - getCompareConfiguration().setEMFComparator(comparator); - return new ComparisonScopeInput(scope, getAdapterFactory()); + EMFCompareConfiguration configuration = getCompareConfiguration(); + configuration.setEMFComparator(comparator); + ComparisonScopeInput input = new ComparisonScopeInput(scope, getAdapterFactory()); + input.setLeftEditable(configuration.isLeftEditable()); + input.setRightEditable(configuration.isRightEditable()); + return input; } /** -- 2.11.4.GIT