blob: f42cced38a393369147c4435038cbfe30f72c5ce [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012, 2014 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.emf.compare.diagram.ecoretools.tests.hide;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.attributeValueMatch;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import java.io.IOException;
import java.util.List;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.diagram.ecoretools.tests.AbstractTest;
import org.eclipse.emf.compare.diagram.ecoretools.tests.DiagramInputData;
import org.eclipse.emf.compare.diagram.ecoretools.tests.hide.data.HideInputData;
import org.eclipse.emf.compare.diagram.internal.extensions.Hide;
import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.junit.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
@SuppressWarnings("nls")
public class HideTest extends AbstractTest {
private HideInputData input = new HideInputData();
@Test
public void testA1UseCase() throws IOException {
final Resource left = input.getA1Left();
final Resource right = input.getA1Right();
final Comparison comparison = compare(left, right, null);
final List<Diff> differences = comparison.getDifferences();
// We should have no less and no more than 2 differences
assertSame(Integer.valueOf(2), Integer.valueOf(differences.size()));
Predicate<? super Diff> attributeChangeDescription = attributeValueMatch(
NotationPackage.Literals.VIEW__VISIBLE.getName(), Boolean.FALSE, false);
Predicate<? super Diff> hideDescription = and(instanceOf(Hide.class), ofKind(DifferenceKind.CHANGE));
assertSame(Integer.valueOf(1), count(differences, instanceOf(Hide.class)));
final Diff attributeChange = Iterators.find(differences.iterator(), attributeChangeDescription);
final Diff hide = Iterators.find(differences.iterator(), hideDescription);
assertNotNull(attributeChange);
assertNotNull(hide);
assertSame(Integer.valueOf(1), Integer.valueOf(hide.getRefinedBy().size()));
assertTrue(hide.getRefinedBy().contains(attributeChange));
testIntersections(comparison);
}
@Override
protected DiagramInputData getInput() {
return null;
}
}