Changeset 1643
- Timestamp:
- 08/01/14 16:03:43 (10 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml-test/pom.xml
r1607 r1643 28 28 <scope>test</scope> 29 29 </dependency> 30 <dependency> 31 <groupId>de.ugoe.cs.autoquest</groupId> 32 <artifactId>autoquest-core-testgeneration</artifactId> 33 <version>${project.parent.version}</version> 34 </dependency> 30 35 </dependencies> 31 36 </project> -
trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java
r1628 r1643 24 24 import java.util.List; 25 25 import java.util.Map; 26 import java.util.Random; 26 27 27 28 import org.eclipse.emf.common.util.URI; … … 36 37 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; 37 38 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; 39 import org.eclipse.uml2.uml.Interaction; 38 40 import org.eclipse.uml2.uml.Model; 39 41 import org.eclipse.uml2.uml.StateMachine; … … 47 49 import de.ugoe.cs.autoquest.eventcore.Event; 48 50 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 51 import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; 49 52 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 50 53 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 54 import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 55 import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 51 56 52 57 /** … … 151 156 HTTPLogParser parser = 152 157 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())); 156 164 Collection<List<Event>> httpSequences = parser.getSequences(); 157 165 Model model = … … 169 177 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence"); 170 178 } 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 } 172 227 } 173 228 … … 181 236 return new XMIResourceImpl(uri) { 182 237 @Override 183 public boolean useUUIDs() 184 { 185 return true; 238 public boolean useUUIDs() { 239 return true; 186 240 } 187 241 }; … … 190 244 191 245 Resource resource = resourceSet.createResource(URI.createURI("binresource")); 192 246 193 247 resource.getContents().add(model); 194 248 FileOutputStream fos; 195 249 File file = new File(filename); 196 if ( file.getParent()!=null) {250 if (file.getParent() != null) { 197 251 file.getParentFile().mkdirs(); 198 252 } -
trunk/autoquest-plugin-uml-test/src/test/resources/testCreateInteractionFromEventSequence_1_model.uml
r1625 r1643 4 4 <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> 5 5 </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>26 6 <packagedElement xmi:type="uml:Class" xmi:id="_Wh3rMBZcEeSVxMc4KdphRg" name="ixsmq"> 27 7 <ownedOperation xmi:type="uml:Operation" xmi:id="_noyI0BZcEeSVxMc4KdphRg" name="removeIdentity"/> -
trunk/autoquest-plugin-uml/pom.xml
r1605 r1643 38 38 <groupId>de.ugoe.cs.autoquest</groupId> 39 39 <artifactId>autoquest-core-events</artifactId> 40 <version>${project.parent.version}</version> 41 </dependency> 42 <dependency> 43 <groupId>de.ugoe.cs.autoquest</groupId> 44 <artifactId>autoquest-core-usageprofiles</artifactId> 40 45 <version>${project.parent.version}</version> 41 46 </dependency> -
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1633 r1643 29 29 import org.eclipse.uml2.uml.Element; 30 30 import org.eclipse.uml2.uml.Interaction; 31 import org.eclipse.uml2.uml.InteractionFragment; 31 32 import org.eclipse.uml2.uml.Lifeline; 32 33 import org.eclipse.uml2.uml.Message; … … 42 43 import de.ugoe.cs.autoquest.eventcore.Event; 43 44 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 45 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 44 46 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 47 import de.ugoe.cs.autoquest.usageprofiles.TrieBasedModel; 45 48 46 49 /** … … 273 276 for (Event event : sequence) { 274 277 if (!(event.equals(Event.STARTEVENT) || event.equals(Event.ENDEVENT))) { 275 if (event.getType() instanceof SOAPEventType) { 276 SOAPEventType eventType = (SOAPEventType) event.getType(); 277 String serviceName = eventType.getServiceName(); 278 String methodName = eventType.getCalledMethod(); 279 Class targetClass = classMap.get(serviceName); 280 if (targetClass == null) { 281 throw new RuntimeException( 282 "Could not find class in the UML model that belong to the service: " + 283 serviceName); 284 } 285 286 Lifeline targetLifeline = interaction.getLifeline(serviceName); 287 if (targetLifeline == null) { 288 targetLifeline = interaction.createLifeline(serviceName); 289 Association association = 290 (Association) model.getPackagedElement("user_" + serviceName, true, 291 UMLPackage.Literals.ASSOCIATION, 292 true); 293 targetLifeline.setRepresents(association.getMemberEnd(serviceName, classMap 294 .get(serviceName))); 295 } 296 MessageOccurrenceSpecification sendFragment = 297 (MessageOccurrenceSpecification) interaction 298 .createFragment(i + ":" + methodName + "_sendFragment", 299 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 300 MessageOccurrenceSpecification recvFragment = 301 (MessageOccurrenceSpecification) interaction 302 .createFragment(i + ":" + methodName + "_recvFragment", 303 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 304 305 sendFragment.setCovered(userLifeline); 306 recvFragment.setCovered(targetLifeline); 307 308 Message message = interaction.createMessage(methodName); 309 message.setSignature(getOperationFromName(targetClass.getOperations(), 310 methodName)); 311 message.setSendEvent(sendFragment); 312 message.setReceiveEvent(recvFragment); 313 314 sendFragment.setMessage(message); 315 recvFragment.setMessage(message); 316 } 317 else { 278 String serviceName = getServiceNameFromEvent(event); 279 String methodName = getCalledMethodFromEvent(event); 280 281 Class targetClass = classMap.get(serviceName); 282 if (targetClass == null) { 318 283 throw new RuntimeException( 319 "Wrong event type. Only SOAPEventType supported but was: " + 320 event.getType().getClass().getName()); 321 } 284 "Could not find class in the UML model that belong to the service: " + 285 serviceName); 286 } 287 288 Lifeline targetLifeline = interaction.getLifeline(serviceName); 289 if (targetLifeline == null) { 290 targetLifeline = interaction.createLifeline(serviceName); 291 Association association = 292 (Association) model.getPackagedElement("user_" + serviceName, true, 293 UMLPackage.Literals.ASSOCIATION, 294 true); 295 targetLifeline 296 .setRepresents(association.getMemberEnd(serviceName, 297 classMap.get(serviceName))); 298 } 299 MessageOccurrenceSpecification sendFragment = 300 (MessageOccurrenceSpecification) interaction 301 .createFragment(i + ":" + methodName + "_sendFragment", 302 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 303 MessageOccurrenceSpecification recvFragment = 304 (MessageOccurrenceSpecification) interaction 305 .createFragment(i + ":" + methodName + "_recvFragment", 306 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 307 308 sendFragment.setCovered(userLifeline); 309 recvFragment.setCovered(targetLifeline); 310 311 Message message = interaction.createMessage(methodName); 312 message.setSignature(getOperationFromName(targetClass.getOperations(), methodName)); 313 message.setSendEvent(sendFragment); 314 message.setReceiveEvent(recvFragment); 315 316 sendFragment.setMessage(message); 317 recvFragment.setMessage(message); 318 322 319 i++; 323 320 } 321 } 322 } 323 324 /** 325 * <p> 326 * Calculates the usage score of an interaction as the logsum of the event probabilities 327 * multiplied with the length of the interaction. 328 * </p> 329 * 330 * @param interaction 331 * interaction for which the score is calculated 332 * @param usageProfile 333 * usage profile used for the calculation 334 * @return calculated usage score 335 */ 336 public static double calculateUsageScore(Interaction interaction, TrieBasedModel usageProfile) { 337 double usageScore = 0.0d; 338 339 EList<InteractionFragment> interactionFragments = interaction.getFragments(); 340 List<Event> eventSequence = new LinkedList<>(); 341 eventSequence.add(Event.STARTEVENT); 342 for (InteractionFragment interactionFragment : interactionFragments) { 343 if (interactionFragment.getName() != null && 344 interactionFragment.getName().endsWith("_recvFragment")) 345 { 346 String serviceName = 347 interactionFragment.getCovereds().get(0).getRepresents().getName(); 348 String methodName = "UNKNOWN"; 349 if (interactionFragment instanceof MessageOccurrenceSpecification) { 350 methodName = 351 ((MessageOccurrenceSpecification) interactionFragment).getMessage() 352 .getName(); 353 } 354 eventSequence.add(new Event(new SimpleSOAPEventType(methodName, serviceName))); 355 } 356 } 357 double prob = usageProfile.getLogSum(eventSequence); 358 usageScore = prob * eventSequence.size(); 359 360 return usageScore; 361 } 362 363 /** 364 * <p> 365 * Helper function to get the name of a service from a SOAP event. 366 * </p> 367 * 368 * @param event 369 * event for which the service name is retrieved 370 * @return service name 371 */ 372 private static String getServiceNameFromEvent(Event event) { 373 if (event.getType() instanceof SOAPEventType) { 374 return ((SOAPEventType) event.getType()).getServiceName(); 375 } 376 else if (event.getType() instanceof SimpleSOAPEventType) { 377 return ((SimpleSOAPEventType) event.getType()).getServiceName(); 378 } 379 else { 380 throw new RuntimeException( 381 "Wrong event type. Only SOAPEventType and SimpleSOAPEventType supported but was: " + 382 event.getType().getClass().getName()); 383 } 384 } 385 386 /** 387 * 388 * <p> 389 * Helper function to get the called method from a SOAP event 390 * </p> 391 * 392 * @param event 393 * event for which the called method is retrieved 394 * @return called method 395 */ 396 private static String getCalledMethodFromEvent(Event event) { 397 if (event.getType() instanceof SOAPEventType) { 398 return ((SOAPEventType) event.getType()).getCalledMethod(); 399 } 400 else if (event.getType() instanceof SimpleSOAPEventType) { 401 return ((SimpleSOAPEventType) event.getType()).getCalledMethod(); 402 } 403 else { 404 throw new RuntimeException( 405 "Wrong event type. Only SOAPEventType and SimpleSOAPEventType supported but was: " + 406 event.getType().getClass().getName()); 324 407 } 325 408 }
Note: See TracChangeset
for help on using the changeset viewer.