Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumliteral #11

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2023 University of York.
* 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:
* Alfa Yohannis - Add a test for enumeration and enumeration literal creation
*******************************************************************************/
package org.eclipse.epsilon.emc.magicdraw.remote;

import static org.junit.Assert.assertNotNull;

import java.io.File;

import org.eclipse.epsilon.eol.EolModule;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* Tests for Enumeration and EnumerationLiteral creation, with MagicDraw running on the
* <code>resources/example-zoo.mdzip</code> project.
*/
public class EnumerationLiteralTest {

private MagicDrawModel m;


@Test
public void createEnumerationLiteral() throws Exception {
String script =
"var enum = new Enumeration;\n"
+ "enum.name = \"MyEnum\";\n"
+ "var literal = new EnumerationLiteral;\n"
+ "literal.name = \"FIRST\";\n"
+ "enum.ownedLiteral.add(literal);\n"
+ "return literal.id;";
EolModule module = createEOLModule();
module.parse(script);
String id = (String) module.execute();
Object result = m.getElementById(id);
assertNotNull("EnumerationLiteral should have been created (not null)", result);
}


private EolModule createEOLModule() {
EolModule module = new EolModule();
module.getContext().getModelRepository().addModel(m);
return module;
}


@Before
public void createZooModel() throws EolModelLoadingException {
m = new MagicDrawModel();
m.setName("Model");

m.setProjectURL(new File("resources/example-zoo.mdzip").getAbsoluteFile().toURI().toString());
m.setReadOnLoad(true);
m.setStoredOnDisposal(false);

m.load();
}

@After
public void disposeModel() {
if (m != null) {
m.close();
}
}
}
Loading