|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2023 University of York. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * Alfa Yohannis - Add a test for enumeration and enumeration literal creation |
| 10 | + *******************************************************************************/ |
| 11 | +package org.eclipse.epsilon.emc.magicdraw.remote; |
| 12 | + |
| 13 | +import static org.junit.Assert.assertNotNull; |
| 14 | + |
| 15 | +import java.io.File; |
| 16 | + |
| 17 | +import org.eclipse.epsilon.eol.EolModule; |
| 18 | +import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException; |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +/** |
| 24 | + * Tests for Enumeration and EnumerationLiteral creation, with MagicDraw running on the |
| 25 | + * <code>resources/example-zoo.mdzip</code> project. |
| 26 | + */ |
| 27 | +public class EnumerationLiteralTest { |
| 28 | + |
| 29 | + private MagicDrawModel m; |
| 30 | + |
| 31 | + |
| 32 | + @Test |
| 33 | + public void createEnumerationLiteral() throws Exception { |
| 34 | + String script = |
| 35 | + "var enum = new Enumeration;\n" |
| 36 | + + "enum.name = \"MyEnum\";\n" |
| 37 | + + "var literal = new EnumerationLiteral;\n" |
| 38 | + + "literal.name = \"FIRST\";\n" |
| 39 | + + "enum.ownedLiteral.add(literal);\n" |
| 40 | + + "return literal.id;"; |
| 41 | + EolModule module = createEOLModule(); |
| 42 | + module.parse(script); |
| 43 | + String id = (String) module.execute(); |
| 44 | + Object result = m.getElementById(id); |
| 45 | + assertNotNull("EnumerationLiteral should have been created (not null)", result); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + private EolModule createEOLModule() { |
| 50 | + EolModule module = new EolModule(); |
| 51 | + module.getContext().getModelRepository().addModel(m); |
| 52 | + return module; |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + @Before |
| 57 | + public void createZooModel() throws EolModelLoadingException { |
| 58 | + m = new MagicDrawModel(); |
| 59 | + m.setName("Model"); |
| 60 | + |
| 61 | + m.setProjectURL(new File("resources/example-zoo.mdzip").getAbsoluteFile().toURI().toString()); |
| 62 | + m.setReadOnLoad(true); |
| 63 | + m.setStoredOnDisposal(false); |
| 64 | + |
| 65 | + m.load(); |
| 66 | + } |
| 67 | + |
| 68 | + @After |
| 69 | + public void disposeModel() { |
| 70 | + if (m != null) { |
| 71 | + m.close(); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments