blob: 303168ecba6ca0b7ce11c10bcfc27a33206c5274 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2017 CEA LIST 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:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.interoperability.sysml14.sysml.tests.tests;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.internal.spec.AttributeChangeSpec;
import org.eclipse.emf.compare.internal.spec.MatchSpec;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.interoperability.common.MigrationParameters.ThreadConfig;
import org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests;
import org.eclipse.papyrus.interoperability.common.transformation.AbstractImportTransformationLauncher;
import org.eclipse.papyrus.interoperability.sysml14.sysml.transformations.SysMLImportTransformationLauncher;
import org.eclipse.papyrus.interoperability.sysml14.sysml.utils.SysMLMigrationConstantsUtils;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Package;
import org.junit.Assert;
import org.osgi.framework.Bundle;
/**
* This allows to define the interoperability QvTo transformation from SysML1.1 to SysML1.4 for the semantic models.
*/
@SuppressWarnings({ "nls", "restriction" })
public class AbstractImportSysMLModelTests extends AbstractImportModelTests {
/**
* This method allows to create the project.
*
* @param projectName
* The name of the project to create for the JUnit test.
* @param modelName
* The model name to import.
* @param resourcePath
* The path where are stored the file to copy/load to execute the tests.
* @param bundle
* The current bundle.
* @throws CoreException
* The core exception.
* @throws IOException
* The input/output file exception.
* @throws URISyntaxException
* The URI syntax exception.
*
*/
public void initTest(final String projectName, final String modelName, final String resourcePath, final Bundle bundle) throws CoreException, IOException, URISyntaxException {
super.initTest(projectName, modelName, "uml", resourcePath, bundle);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#createLauncher(org.eclipse.papyrus.migration.common.MigrationParameters.ThreadConfig)
*/
@Override
public AbstractImportTransformationLauncher createLauncher(final ThreadConfig config) {
return new SysMLImportTransformationLauncher(config);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#getOutputModelName()
*/
@Override
protected String getOutputModelName() {
return modelName + "_converted";
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#checkUMLModelSpecificities(org.eclipse.uml2.uml.Package)
*/
@Override
protected void checkUMLModelSpecificities(final Package rootPackage) {
checkEAnnotationUsedForSysMLMigration(rootPackage);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#checkNotationElementSpecificities(org.eclipse.emf.ecore.EModelElement)
*/
@Override
protected void checkNotationElementSpecificities(final EModelElement notationElement) {
// Do nothing here, must be done in ImportSysMLModelWithNotationTests
}
/**
* This method check that the EObject owns the required EAnnotation indicating the model Model, Diagram or Table has been created from a SysML Migration.
*
* @param objectToTest
* An object.
*/
protected void checkEAnnotationUsedForSysMLMigration(final EModelElement objectToTest) {
Assert.assertTrue("Internal test checking that tested object is a NamedElement, a Diagram or a Table failed", objectToTest instanceof NamedElement || objectToTest instanceof Diagram || objectToTest instanceof Table);
String objectName = ""; //$NON-NLS-1$
if (objectToTest instanceof NamedElement) {
objectName = ((NamedElement) objectToTest).getName();
} else if (objectToTest instanceof Diagram) {
objectName = ((Diagram) objectToTest).getName();
} else if (objectToTest instanceof Table) {
objectName = ((Table) objectToTest).getName();
}
final String eClassName = objectToTest.eClass().getName();
final EAnnotation annotation = objectToTest.getEAnnotation(SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_SOURCE);
Assert.assertNotNull(NLS.bind("{0}:{1} : The EAnnotation used for versioning has not been found.", objectName, eClassName), annotation);
// we check the differents details needed
final String papyrusSourceProjectName = annotation.getDetails().get(SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_DETAIL_KEY_PAPYRUS_SOURCE_PROJECT_NAME);
Assert.assertNotNull(NLS.bind("{0}:{1} : The string indicating the Papyrus source project has not been found.", objectName, eClassName), papyrusSourceProjectName);
Assert.assertTrue(NLS.bind("{0}:{1} : The string indicating the Papyrus source project is empty.", objectName, eClassName), !papyrusSourceProjectName.isEmpty());
final String migrationDate = annotation.getDetails().get(SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_DETAIL_KEY_PAPYRUS_MIGRATION_DATE);
Assert.assertNotNull(NLS.bind("{0}:{1} : The string indicating the Migration Date has not been found.", objectName, eClassName), migrationDate);
Assert.assertTrue(NLS.bind("{0}:{1} : The string indicating the Migration Date is empty.", objectName, eClassName), !migrationDate.isEmpty());
final String migrationBundleVersion = annotation.getDetails().get(SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_DETAIL_KEY_PAPYRUS_MIGRATION_BUNDLE_VERSION);
Assert.assertNotNull(NLS.bind("{0}:{1} : The string indicating the Migration bundle version has not been found.", objectName, eClassName), migrationBundleVersion);
Assert.assertTrue(NLS.bind("{0}:{1} : The string indicating the Migration bundle version is empty.", objectName, eClassName), !migrationBundleVersion.isEmpty());
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#getFilteredDiffForUMLModel(java.util.List)
*/
@Override
protected List<Diff> getFilteredDiffForUMLModel(final List<Diff> diff) {
final List<Diff> returnedDiffs = new ArrayList<>(diff);
for (final Diff current : diff) {
if (current instanceof AttributeChangeSpec && ((AttributeChangeSpec) current).eContainer() instanceof MatchSpec) {
if (current.getKind() == DifferenceKind.CHANGE) {
final EObject value = ((MatchSpec) ((AttributeChangeSpec) current).eContainer()).basicGetLeft();
if (value instanceof EStringToStringMapEntryImpl) {
final EStringToStringMapEntryImpl map = (EStringToStringMapEntryImpl) value;
final String key = map.getKey();
if (SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_DETAIL_KEY_PAPYRUS_MIGRATION_DATE.equals(key) || SysMLMigrationConstantsUtils.VERSIONING_EANNOTATION_DETAIL_KEY_PAPYRUS_MIGRATION_BUNDLE_VERSION.equals(key)) {
returnedDiffs.remove(current);
}
}
}
}
}
return returnedDiffs;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.papyrus.interoperability.common.tests.tests.AbstractImportModelTests#compareNotation()
*/
@Override
protected boolean compareNotation() {
return false;
}
}