Skip to content

Commit

Permalink
[2203] add Junit for Wrong CDO generation of derived features on non
Browse files Browse the repository at this point in the history
Capella Elements

- add condition on Eannotation derived and description

Bug:2203


Change-Id: Ic709f24da0da41f4c95be419a719b16fbca411ae
Signed-off-by: Joacquim Esabe <joacquim.esabe@laposte.net>
  • Loading branch information
Joacquim Esabe committed Sep 27, 2018
1 parent f542965 commit 75cb25b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2018 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.test.platform.ju.testcases;

import java.util.Set;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.polarsys.capella.common.ef.ExecutionManager;
import org.polarsys.capella.common.ef.ExecutionManagerRegistry;
import org.polarsys.capella.common.model.helpers.IModelConstants;
import org.polarsys.capella.core.model.handler.helpers.HoldingResourceHelper;
import org.polarsys.capella.test.framework.api.BasicTestCase;
import com.google.common.collect.Sets;

/**
* This class test the generating model EPackage for all Capella package, if catch exception
* UnsupportedOperationException Assertion failed error is thrown
*/
public class CapellaCDOGenerationOfDerivedFeature extends BasicTestCase {

@Override
public void test() throws Exception {

Registry registry = EPackage.Registry.INSTANCE;
Set<String> uris = Sets.newHashSet(registry.keySet());
for (String uri : uris) {
EPackage ePackage = registry.getEPackage(uri);
if (uri.contains("capella")) {
for (EClassifier c : ePackage.getEClassifiers()) {
if (c instanceof EClass) {
EClass eclass = (EClass) c;
if (!eclass.isAbstract()) {
EObject object = eclass.getEPackage().getEFactoryInstance().create(eclass);
ExecutionManager executionManager = ExecutionManagerRegistry.getInstance().addNewManager();
TransactionalEditingDomain domainTransaction = executionManager.getEditingDomain();
domainTransaction.getCommandStack().execute(new RecordingCommand(domainTransaction) {

@Override
protected void doExecute() {
HoldingResourceHelper.getHoldingResource(domainTransaction).getContents().add(object);
for (EReference reference : eclass.getEAllReferences()) {
if (reference.isDerived()
&& reference.getEAnnotation(IModelConstants.HELPER_ANNOTATION_SOURCE) != null) {
try {
object.eGet(reference);
} catch (UnsupportedOperationException e) {
assertTrue(e.getMessage(), false);
}
}
}
}
});
}
}
}
}
}
}
}
Expand Up @@ -15,6 +15,7 @@

import org.polarsys.capella.test.framework.api.BasicTestArtefact;
import org.polarsys.capella.test.framework.api.BasicTestSuite;
import org.polarsys.capella.test.platform.ju.testcases.CapellaCDOGenerationOfDerivedFeature;
import org.polarsys.capella.test.platform.ju.testcases.CapellaDefaultEditorEnabled;
import org.polarsys.capella.test.platform.ju.testcases.CapellaPlatformVersionNotNull;

Expand All @@ -40,6 +41,7 @@ protected List<BasicTestArtefact> getTests() {
List<BasicTestArtefact> tests = new ArrayList<BasicTestArtefact>();
tests.add(new CapellaPlatformVersionNotNull());
tests.add(new CapellaDefaultEditorEnabled());
tests.add(new CapellaCDOGenerationOfDerivedFeature());
return tests;
}

Expand Down

0 comments on commit 75cb25b

Please sign in to comment.