Ignore:
Timestamp:
08/01/14 16:03:43 (10 years ago)
Author:
sherbold
Message:
  • added usage score calculation to the UMLUtils
  • added a test case for the usage score calculation
Location:
trunk/autoquest-plugin-uml-test
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-uml-test/pom.xml

    r1607 r1643  
    2828            <scope>test</scope> 
    2929        </dependency> 
     30        <dependency> 
     31            <groupId>de.ugoe.cs.autoquest</groupId> 
     32            <artifactId>autoquest-core-testgeneration</artifactId> 
     33            <version>${project.parent.version}</version> 
     34        </dependency> 
    3035    </dependencies> 
    3136</project> 
  • trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java

    r1628 r1643  
    2424import java.util.List; 
    2525import java.util.Map; 
     26import java.util.Random; 
    2627 
    2728import org.eclipse.emf.common.util.URI; 
     
    3637import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; 
    3738import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; 
     39import org.eclipse.uml2.uml.Interaction; 
    3840import org.eclipse.uml2.uml.Model; 
    3941import org.eclipse.uml2.uml.StateMachine; 
     
    4749import de.ugoe.cs.autoquest.eventcore.Event; 
    4850import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 
     51import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 
    4952import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
    5053import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 
     54import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 
     55import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 
    5156 
    5257/** 
     
    151156        HTTPLogParser parser = 
    152157            new HTTPLogParser(new File(ClassLoader 
    153                 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt").getFile())); 
    154         parser.parseFile(new File(ClassLoader 
    155             .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log").getFile())); 
     158                .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 
     159                .getFile())); 
     160        parser 
     161            .parseFile(new File(ClassLoader 
     162                .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
     163                .getFile())); 
    156164        Collection<List<Event>> httpSequences = parser.getSequences(); 
    157165        Model model = 
     
    169177            UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence"); 
    170178        } 
    171         //writeModelToFile(model, "testCreateInteractionFromEventSequence_1_result.uml"); 
     179        // writeModelToFile(model, "testCreateInteractionFromEventSequence_1_result.uml"); 
     180    } 
     181 
     182    @Test 
     183    public void testCalculateUsageScore_1() throws Exception { 
     184        // parse log file 
     185        HTTPLogParser parser = 
     186            new HTTPLogParser(new File(ClassLoader 
     187                .getSystemResource("testCalculateUsageScore_1_properties.txt").getFile())); 
     188        parser.parseFile(new File(ClassLoader 
     189            .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile())); 
     190        Collection<List<Event>> httpSequences = parser.getSequences(); 
     191        Model model = 
     192            loadModelFromInputStream(ClassLoader 
     193                .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml")); 
     194 
     195        Collection<List<Event>> simpleSOAPSequences = new LinkedList<>(); 
     196        for (List<Event> httpSequence : httpSequences) { 
     197            for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
     198                Event event = eventIter.next(); 
     199                if (!(event.getType() instanceof SOAPEventType)) { 
     200                    eventIter.remove(); 
     201                } 
     202            } 
     203            simpleSOAPSequences.add(HTTPUtils.convertToSimpleSOAPEvent(httpSequence)); 
     204            // simpleSOAPSequences.add(httpSequence); 
     205        } 
     206 
     207        FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1)); 
     208        usageProfile.train(simpleSOAPSequences); 
     209 
     210        Collection<List<Event>> genSeqs = 
     211            (new RandomWalkGenerator(10, 1, 100, true, 500)).generateTestSuite(usageProfile); 
     212 
     213        int i = 1; 
     214        int[] lengths = new int[genSeqs.size()]; 
     215        for (List<Event> seq : genSeqs) { 
     216            UMLUtils.createInteractionFromEventSequence(seq, model, "seq_" + i); 
     217            lengths[i - 1] = seq.size(); 
     218            i++; 
     219        } 
     220        for (int j = 0; j < genSeqs.size(); j++) { 
     221            Interaction interaction = 
     222                (Interaction) model.getPackagedElement("seq_" + j, true, 
     223                                                       UMLPackage.Literals.INTERACTION, true); 
     224            double usageScore = UMLUtils.calculateUsageScore(interaction, usageProfile); 
     225            System.out.format("usage score %02d: %.2f \t %d\n",j+1, usageScore, lengths[j]); 
     226        } 
    172227    } 
    173228 
     
    181236                    return new XMIResourceImpl(uri) { 
    182237                        @Override 
    183                         public boolean useUUIDs() 
    184                         { 
    185                                 return true; 
     238                        public boolean useUUIDs() { 
     239                            return true; 
    186240                        } 
    187241                    }; 
     
    190244 
    191245        Resource resource = resourceSet.createResource(URI.createURI("binresource")); 
    192          
     246 
    193247        resource.getContents().add(model); 
    194248        FileOutputStream fos; 
    195249        File file = new File(filename); 
    196         if( file.getParent()!=null ) { 
     250        if (file.getParent() != null) { 
    197251            file.getParentFile().mkdirs(); 
    198252        } 
  • trunk/autoquest-plugin-uml-test/src/test/resources/testCreateInteractionFromEventSequence_1_model.uml

    r1625 r1643  
    44    <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> 
    55  </packageImport> 
    6   <packagedElement xmi:type="uml:StateMachine" xmi:id="_O36_UAaaEeS7deEA7EQ5bQ" name="PatientIDBehavior"> 
    7     <region xmi:type="uml:Region" xmi:id="_O3-psAaaEeS7deEA7EQ5bQ" name="Region0"> 
    8       <transition xmi:type="uml:Transition" xmi:id="_paX4YAacEeS7deEA7EQ5bQ" name="IXSMangementAndQueryInterface.UpdateEntityTraitValues" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_SnZhwAaaEeS7deEA7EQ5bQ"/> 
    9       <transition xmi:type="uml:Transition" xmi:id="_1hD9YAacEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.RegisterEntityWithIdentity" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    10       <transition xmi:type="uml:Transition" xmi:id="_ZbI3sAagEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.CreateIdentityFromEntity" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    11       <transition xmi:type="uml:Transition" xmi:id="_hU4bIAagEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.GetEntityTraitValues" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_SnZhwAaaEeS7deEA7EQ5bQ"/> 
    12       <transition xmi:type="uml:Transition" xmi:id="_AuMAUAahEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.FindIdentitiesByTraits" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_SnZhwAaaEeS7deEA7EQ5bQ"/> 
    13       <transition xmi:type="uml:Transition" xmi:id="_mnkAQAahEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.RemoveEntity" source="_SnZhwAaaEeS7deEA7EQ5bQ" target="_SnZhwAaaEeS7deEA7EQ5bQ"/> 
    14       <transition xmi:type="uml:Transition" xmi:id="_Bsp-QAaiEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.RegisterEntityWithIdentity" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    15       <transition xmi:type="uml:Transition" xmi:id="_M3iiUAaiEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.CreateIdentityFromEntity" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    16       <transition xmi:type="uml:Transition" xmi:id="_TLpksAaiEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.UpdateEntityTraitValues" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    17       <transition xmi:type="uml:Transition" xmi:id="_WbouwAaiEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.RemoveIdentity" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_SnZhwAaaEeS7deEA7EQ5bQ"/> 
    18       <transition xmi:type="uml:Transition" xmi:id="_36iugAaiEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.GetEntityTraitValues" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    19       <transition xmi:type="uml:Transition" xmi:id="_BSZ1wAajEeS7deEA7EQ5bQ" name="IXSManagementAndQueryInterface.FindIdentityByTraits" source="_X7obgAaaEeS7deEA7EQ5bQ" target="_X7obgAaaEeS7deEA7EQ5bQ"/> 
    20       <subvertex xmi:type="uml:State" xmi:id="_SnZhwAaaEeS7deEA7EQ5bQ" name="PatientUnkown_MPI_RLUS"/> 
    21       <subvertex xmi:type="uml:State" xmi:id="_X7obgAaaEeS7deEA7EQ5bQ" name="PatientKnown_MPI_PatientUnkown_RLUS"/> 
    22       <subvertex xmi:type="uml:State" xmi:id="_e-D8cAaaEeS7deEA7EQ5bQ" name="PatientKnown_RLUS_PatientUnkown_MPI"/> 
    23       <subvertex xmi:type="uml:State" xmi:id="_a1ERUAabEeS7deEA7EQ5bQ" name="PatientKnown_MPI_RLUS"/> 
    24     </region> 
    25   </packagedElement> 
    266  <packagedElement xmi:type="uml:Class" xmi:id="_Wh3rMBZcEeSVxMc4KdphRg" name="ixsmq"> 
    277    <ownedOperation xmi:type="uml:Operation" xmi:id="_noyI0BZcEeSVxMc4KdphRg" name="removeIdentity"/> 
Note: See TracChangeset for help on using the changeset viewer.