Changeset 1759 for trunk/autoquest-plugin-uml-test/src/test/java/de
- Timestamp:
- 09/22/14 15:25:22 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java
r1752 r1759 16 16 17 17 import java.io.File; 18 import java.io.FileInputStream;19 import java.io.FileOutputStream;20 import java.io.IOException;21 import java.io.InputStream;22 18 import java.util.Collection; 23 19 import java.util.Iterator; 24 20 import java.util.LinkedList; 25 21 import java.util.List; 26 import java.util.Map;27 22 import java.util.Random; 28 23 29 import org.eclipse.core.runtime.IStatus;30 import org.eclipse.emf.common.util.URI;31 import org.eclipse.emf.ecore.EPackage;32 import org.eclipse.emf.ecore.EcorePackage;33 import org.eclipse.emf.ecore.resource.Resource;34 import org.eclipse.emf.ecore.resource.ResourceSet;35 import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;36 import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;37 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;38 import org.eclipse.emf.ecore.util.EcoreUtil;39 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;40 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;41 24 import org.eclipse.uml2.uml.Interaction; 42 25 import org.eclipse.uml2.uml.Model; … … 44 27 import org.eclipse.uml2.uml.Transition; 45 28 import org.eclipse.uml2.uml.UMLPackage; 46 import org.eclipse.uml2.uml.resource.UMLResource;47 import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;48 29 import org.junit.After; 49 30 import org.junit.Test; 50 31 32 import de.fraunhofer.fokus.testing.ModelUtils; 51 33 import de.ugoe.cs.autoquest.eventcore.Event; 52 34 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; … … 56 38 import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 57 39 import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 58 import eu.midas.dsl.validation.util.ConstraintValidator;59 40 60 41 /** … … 85 66 Collection<List<Event>> httpSequences = parser.getSequences(); 86 67 Model model = 87 loadModelFromInputStream(ClassLoader68 ModelUtils.loadModel(ClassLoader 88 69 .getSystemResourceAsStream("createSequence_1_model.uml")); 89 70 … … 118 99 Collection<List<Event>> httpSequences = parser.getSequences(); 119 100 Model model = 120 loadModelFromInputStream(ClassLoader101 ModelUtils.loadModel(ClassLoader 121 102 .getSystemResourceAsStream("createSequence_1_model.uml")); 122 103 … … 151 132 UMLUtils.convertStateMachineToUsageProfile(umlSequences, stateMachine); 152 133 153 writeModelToFile(model, OUTPUT_DIR + "convertStateMachineToUsageProfile_1.uml");134 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "convertStateMachineToUsageProfile_1.uml"); 154 135 } 155 136 … … 166 147 .getFile())); 167 148 Collection<List<Event>> httpSequences = parser.getSequences(); 168 Model model = 169 loadModelFromInputStream(ClassLoader 149 150 Model model = 151 ModelUtils.loadModel(ClassLoader 170 152 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 171 153 … … 181 163 } 182 164 183 ConstraintValidator validator = new ConstraintValidator(); 184 IStatus validationStatus = validator.validate(model); 185 if (validationStatus.getSeverity() == IStatus.OK) { 186 System.out.println("success"); 187 } 188 else { 189 System.out.println("Errors during the model validation: "); 190 for (IStatus status : validationStatus.getChildren()) { 191 System.out.println("\t" + status.getMessage()); 192 } 193 } 194 195 writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 196 loadModelFromInputStream(new FileInputStream(OUTPUT_DIR + 197 "testCreateInteractionFromEventSequence_1_result.uml")); 165 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 198 166 } 199 167 … … 207 175 .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile())); 208 176 Collection<List<Event>> httpSequences = parser.getSequences(); 209 Model model = 210 loadModelFromInputStream(ClassLoader 177 178 Model model = 179 ModelUtils.loadModel(ClassLoader 211 180 .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml")); 212 181 … … 245 214 } 246 215 247 private static void writeModelToFile(Model model, String filename) throws IOException {248 final ResourceSet resourceSet = new ResourceSetImpl();249 UMLResourcesUtil.init(resourceSet);250 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()251 .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new ResourceFactoryImpl() {252 @Override253 public Resource createResource(URI uri) {254 return new XMIResourceImpl(uri) {255 @Override256 public boolean useUUIDs() {257 return true;258 }259 };260 }261 });262 263 Resource resource = resourceSet.createResource(URI.createURI("binresource"));264 265 resource.getContents().add(model);266 FileOutputStream fos;267 File file = new File(filename);268 if (file.getParent() != null) {269 file.getParentFile().mkdirs();270 }271 fos = new FileOutputStream(file);272 resource.save(fos, null);273 }274 275 private static Model loadModelFromInputStream(InputStream inputStream) {276 ResourceSet resourceSet = new ResourceSetImpl();277 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()278 .put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);279 resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);280 resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);281 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()282 .put(Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());283 Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();284 285 UMLResourcesUtil.init(resourceSet);286 287 uriMap.put(URI.createURI("pathmap://Papyrus.profile.uml"),288 URI.createURI("file:/D:/.../Papyrus.profile.uml/"));289 290 EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);291 292 Resource resource = new XMIResourceImpl();293 294 try {295 // resource.load(inputStream, options);296 resource.load(inputStream, null);297 }298 catch (IOException e) {299 // TODO Auto-generated catch block300 e.printStackTrace();301 }302 303 return (Model) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.MODEL);304 }305 306 216 private void deleteFiles(File file) { 307 217 if (file.exists()) {
Note: See TracChangeset
for help on using the changeset viewer.