Ignore:
Timestamp:
09/22/14 15:25:22 (10 years ago)
Author:
sherbold
Message:
  • added new third-party repo for FF tooling
  • now using UML modeling tools from FF
  • generated sequence diagrams are now the implementation of an operation with the TestCase? stereotype. In case the loaded model knows UTP, the UTP TestCase? stereotype is set.
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  
    1616 
    1717import java.io.File; 
    18 import java.io.FileInputStream; 
    19 import java.io.FileOutputStream; 
    20 import java.io.IOException; 
    21 import java.io.InputStream; 
    2218import java.util.Collection; 
    2319import java.util.Iterator; 
    2420import java.util.LinkedList; 
    2521import java.util.List; 
    26 import java.util.Map; 
    2722import java.util.Random; 
    2823 
    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; 
    4124import org.eclipse.uml2.uml.Interaction; 
    4225import org.eclipse.uml2.uml.Model; 
     
    4427import org.eclipse.uml2.uml.Transition; 
    4528import org.eclipse.uml2.uml.UMLPackage; 
    46 import org.eclipse.uml2.uml.resource.UMLResource; 
    47 import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil; 
    4829import org.junit.After; 
    4930import org.junit.Test; 
    5031 
     32import de.fraunhofer.fokus.testing.ModelUtils; 
    5133import de.ugoe.cs.autoquest.eventcore.Event; 
    5234import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 
     
    5638import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 
    5739import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 
    58 import eu.midas.dsl.validation.util.ConstraintValidator; 
    5940 
    6041/** 
     
    8566        Collection<List<Event>> httpSequences = parser.getSequences(); 
    8667        Model model = 
    87             loadModelFromInputStream(ClassLoader 
     68            ModelUtils.loadModel(ClassLoader 
    8869                .getSystemResourceAsStream("createSequence_1_model.uml")); 
    8970 
     
    11899        Collection<List<Event>> httpSequences = parser.getSequences(); 
    119100        Model model = 
    120             loadModelFromInputStream(ClassLoader 
     101            ModelUtils.loadModel(ClassLoader 
    121102                .getSystemResourceAsStream("createSequence_1_model.uml")); 
    122103 
     
    151132        UMLUtils.convertStateMachineToUsageProfile(umlSequences, stateMachine); 
    152133 
    153         writeModelToFile(model, OUTPUT_DIR + "convertStateMachineToUsageProfile_1.uml"); 
     134        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "convertStateMachineToUsageProfile_1.uml"); 
    154135    } 
    155136 
     
    166147                .getFile())); 
    167148        Collection<List<Event>> httpSequences = parser.getSequences(); 
    168         Model model = 
    169             loadModelFromInputStream(ClassLoader 
     149 
     150        Model model = 
     151            ModelUtils.loadModel(ClassLoader 
    170152                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 
    171153 
     
    181163        } 
    182164 
    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"); 
    198166    } 
    199167 
     
    207175            .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile())); 
    208176        Collection<List<Event>> httpSequences = parser.getSequences(); 
    209         Model model = 
    210             loadModelFromInputStream(ClassLoader 
     177 
     178        Model model = 
     179            ModelUtils.loadModel(ClassLoader 
    211180                .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml")); 
    212181 
     
    245214    } 
    246215 
    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                 @Override 
    253                 public Resource createResource(URI uri) { 
    254                     return new XMIResourceImpl(uri) { 
    255                         @Override 
    256                         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 block 
    300             e.printStackTrace(); 
    301         } 
    302  
    303         return (Model) EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.MODEL); 
    304     } 
    305  
    306216    private void deleteFiles(File file) { 
    307217        if (file.exists()) { 
Note: See TracChangeset for help on using the changeset viewer.