|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2008, 2015 |
| 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 | + * Javier Canovas ([email protected]) |
| 10 | + *******************************************************************************/ |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +package jsondiscoverer.util.test; |
| 15 | + |
| 16 | +import static org.junit.Assert.*; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import java.io.IOException; |
| 20 | +import java.io.PrintWriter; |
| 21 | + |
| 22 | +import org.eclipse.emf.common.util.URI; |
| 23 | +import org.eclipse.emf.ecore.EClass; |
| 24 | +import org.eclipse.emf.ecore.EClassifier; |
| 25 | +import org.eclipse.emf.ecore.EPackage; |
| 26 | +import org.eclipse.emf.ecore.resource.Resource; |
| 27 | +import org.eclipse.emf.ecore.resource.ResourceSet; |
| 28 | +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 29 | +import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl; |
| 30 | +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +import jsondiscoverer.CoreographyBuilder; |
| 34 | + |
| 35 | +public class TestCoreographyBuilder { |
| 36 | + |
| 37 | + public static String EXPECTED = "User->GOOGLEMAPS:pathCalculator(origin : EString, destination : EString, waypoints : EString, sensor : EBoolean)\n" + |
| 38 | + "GOOGLEMAPS-->User:response(lat : ESTRING, lng : ESTRING)\n" + |
| 39 | + "Note right of User:LOOP\n" + |
| 40 | + "Note right of User: lat -> lat, lng -> lon\n" + |
| 41 | + "User->TAN:stopPosition(lat : EInt, lon : EInt)\n" + |
| 42 | + "TAN-->User:response(numLigne : ESTRING, directionSens1 : ESTRING, directionSens2 : ESTRING, accessible : EBOOLEAN, etatTrafic : EINT, libelleTrafic : ESTRING, typeLigne : EINT)"; |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testCalculate() { |
| 46 | + |
| 47 | + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); |
| 48 | + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); |
| 49 | + ResourceSet rset = new ResourceSetImpl(); |
| 50 | + Resource res1 = rset.getResource(URI.createFileURI("./testData/coreographyBuilder/zoo.ecore"), true); |
| 51 | + try { |
| 52 | + res1.load(null); |
| 53 | + } catch (IOException e) { |
| 54 | + e.printStackTrace(); |
| 55 | + } |
| 56 | + EPackage package1 = (EPackage) res1.getContents().get(0); |
| 57 | + |
| 58 | + EClass source = null; |
| 59 | + EClass target = null; |
| 60 | + |
| 61 | + for(EClassifier eClassifier : package1.getEClassifiers()) { |
| 62 | + if (eClassifier instanceof EClass) { |
| 63 | + EClass eClass = (EClass) eClassifier; |
| 64 | + if(eClass.getName().equals("pathCalculatorInput")) { |
| 65 | + source = eClass; |
| 66 | + } |
| 67 | + if(eClass.getName().equals("Ligne")) { |
| 68 | + target = eClass; |
| 69 | + } |
| 70 | + |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + CoreographyBuilder builder = new CoreographyBuilder(package1); |
| 75 | + String result = builder.calculate(source, target); |
| 76 | + assertEquals(EXPECTED, result); |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments