001: package org.andromda.repositories.emf.uml2;
002:
003: import java.net.URL;
004: import java.util.ArrayList;
005: import java.util.Collection;
006: import java.util.Iterator;
007: import java.util.Set;
008:
009: import junit.framework.TestCase;
010:
011: import org.andromda.core.common.AndroMDALogger;
012: import org.andromda.core.metafacade.ModelAccessFacade;
013: import org.eclipse.emf.ecore.EcorePackage;
014: import org.eclipse.emf.ecore.util.EcoreUtil;
015: import org.eclipse.uml2.Model;
016: import org.eclipse.uml2.NamedElement;
017: import org.eclipse.uml2.Stereotype;
018: import org.eclipse.uml2.util.UML2Resource;
019: import org.eclipse.uml2.util.UML2Util;
020:
021: /**
022: * Implements the JUnit test case for
023: * <code>org.andromda.repositories.eclipseUml2.EMFRepositoryFacade</code>.
024: *
025: * @author Steve Jerman
026: * @author Chad Brandon
027: */
028: public class EMFUML2RepositoryFacadeTest extends TestCase {
029: /**
030: * Constructor for EMFUML2RepositoryFacadeTest.
031: *
032: * @param name the test name
033: */
034: public EMFUML2RepositoryFacadeTest(String name) {
035: super (name);
036: AndroMDALogger.initialize();
037: }
038:
039: public Collection getStereotypeNames(Object modelElement) {
040: NamedElement element = (NamedElement) modelElement;
041: Set stereotypes = element.getAppliedStereotypes();
042: ArrayList names = new ArrayList();
043: for (final Iterator iterator = stereotypes.iterator(); iterator
044: .hasNext();) {
045: Stereotype stereotype = (Stereotype) iterator.next();
046: names.add(stereotype.getName());
047: }
048: return names;
049: }
050:
051: /**
052: * The URL to the model
053: */
054: private URL modelUrl = null;
055:
056: /**
057: * The repository instance.
058: */
059: private EMFUML2RepositoryFacade repository = null;
060:
061: /**
062: * @see TestCase#setUp()
063: */
064: protected void setUp() throws Exception {
065: super .setUp();
066: if (this .modelUrl == null) {
067: this .modelUrl = TestModel.getModel();
068: assertNotNull(this .modelUrl);
069:
070: this .repository = new EMFUML2RepositoryFacade();
071: this .repository.open();
072: }
073: }
074:
075: /**
076: * @see TestCase#tearDown()
077: */
078: protected void tearDown() throws Exception {
079: this .repository.close();
080: this .repository = null;
081: super .tearDown();
082: }
083:
084: public void testGetModel() {
085: repository
086: .readModel(new String[] { modelUrl.toString() }, null);
087: final ModelAccessFacade modelFacade = repository.getModel();
088: assertNotNull(modelFacade);
089: assertNotNull(modelFacade.getModel());
090: assertTrue(modelFacade.getModel() instanceof UML2Resource);
091: Model model = (Model) EcoreUtil.getObjectByType(
092: ((UML2Resource) repository.getModel().getModel())
093: .getContents(), EcorePackage.eINSTANCE
094: .getEObject());
095: assertEquals("Test Model", model.getName());
096: Collection elements = UML2Util.findNamedElements(model
097: .eResource(), "Test Model::testPackage::Top", true);
098: org.eclipse.uml2.Class umlClass = (org.eclipse.uml2.Class) elements
099: .iterator().next();
100: assertEquals("Top", umlClass.getName());
101: assertFalse(getStereotypeNames(umlClass).isEmpty());
102: }
103: }
|