Changeset 1835 for trunk/autoquest-plugin-uml
- Timestamp:
- 11/27/14 12:44:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1763 r1835 35 35 import org.eclipse.uml2.uml.Connector; 36 36 import org.eclipse.uml2.uml.ConnectorEnd; 37 import org.eclipse.uml2.uml.Element; 37 38 import org.eclipse.uml2.uml.Interaction; 38 39 import org.eclipse.uml2.uml.InteractionFragment; … … 47 48 import org.eclipse.uml2.uml.Profile; 48 49 import org.eclipse.uml2.uml.Property; 49 import org.eclipse.uml2.uml.Realization;50 50 import org.eclipse.uml2.uml.Region; 51 51 import org.eclipse.uml2.uml.StateMachine; … … 272 272 String interactionName) 273 273 { 274 Map<String, Port> portMap = new HashMap<>(); 275 276 Component testContext = 277 (Component) model.getPackagedElement("TestContext", true, 278 UMLPackage.Literals.COMPONENT, true); 274 275 Component testContext = fetchTestContext(model); 279 276 280 277 final Profile utpProfile = model.getAppliedProfile("utp"); … … 290 287 UMLPackage.Literals.INTERACTION); 291 288 operation.getMethods().add(interaction); 292 289 293 290 // create lifelines 294 291 Lifeline userLifeline = null; 295 List<Port> userPorts = new LinkedList<>();292 // List<Port> userPorts = new LinkedList<>(); 296 293 for (Property property : testContext.getAllAttributes()) { 297 294 if (property.getAppliedStereotypes().contains(utpSUT)) { 298 String serviceName = getRealizedInterfaceFromProperty(property).getName(); 299 295 String serviceName = property.getName(); 300 296 Lifeline targetLifeline = interaction.createLifeline(serviceName); 301 297 targetLifeline.setRepresents(property); 302 portMap.put(serviceName,303 (Port) ((Component) property.getType()).getAttribute("p_" + serviceName, null));304 298 } 305 299 else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 306 300 userLifeline = interaction.createLifeline(property.getName()); 307 301 userLifeline.setRepresents(property); 308 EList<Property> userAttributes = ((Component) property.getType()).getAttributes(); 309 for (Property userAttribute : userAttributes) { 310 if (userAttribute instanceof Port) { 311 userPorts.add((Port) userAttribute); 312 } 313 } 314 } 315 } 302 } 303 } 304 305 // TODO sanity checks for userLifeline!=null, etc. 316 306 317 307 int i = 0; … … 320 310 String serviceName = getServiceNameFromEvent(event); 321 311 String methodName = getCalledMethodFromEvent(event); 322 323 Lifeline targetLifeline = interaction.getLifeline(serviceName); 324 Interface targetInterface = getRealizedInterfaceFromProperty((Property) targetLifeline.getRepresents()); 325 312 313 // determine lifelines 314 Lifeline msgTargetLifeline; 315 Lifeline msgSourceLifeline; 316 317 if( serviceName.equals(userLifeline.getName()) ) { 318 // message being send to user 319 // currently we just select the first lifeline that is not the user 320 // this, obviously, has to be replaced with the real service. 321 // however, identification of the source of a message is still an open issue 322 msgSourceLifeline = null; 323 for( Lifeline lifeline : interaction.getLifelines() ) { 324 if(!lifeline.equals(userLifeline)){ 325 msgSourceLifeline = lifeline; 326 break; 327 } 328 } 329 msgTargetLifeline = userLifeline; 330 } else { 331 msgSourceLifeline = userLifeline; 332 msgTargetLifeline = interaction.getLifeline(serviceName); 333 } 334 335 // determine target interface 336 Interface targetInterface = getRealizedInterfaceFromProperty((Property) msgTargetLifeline.getRepresents()); 337 338 // create message 326 339 MessageOccurrenceSpecification sendFragment = 327 340 (MessageOccurrenceSpecification) interaction … … 333 346 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 334 347 335 sendFragment.setCovered( userLifeline);336 recvFragment.setCovered( targetLifeline);348 sendFragment.setCovered(msgSourceLifeline); 349 recvFragment.setCovered(msgTargetLifeline); 337 350 338 351 Message message = interaction.createMessage(methodName); 339 352 if (getOperationFromName(targetInterface.getOperations(), methodName) == null) { 340 System.out.println("operation not found : " + methodName);353 System.out.println("operation not found in the " + targetInterface.getName() + " interface: " + methodName); 341 354 } 342 355 message.setSignature(getOperationFromName(targetInterface.getOperations(), … … 346 359 message.setReceiveEvent(recvFragment); 347 360 348 EList<ConnectorEnd> targetEnds = portMap.get(serviceName).getEnds(); 349 350 for (Port userPort : userPorts) { 351 EList<ConnectorEnd> sourceEnds = userPort.getEnds(); 352 for (ConnectorEnd sourceEnd : sourceEnds) { 353 Connector sourceConnector = (Connector) sourceEnd.eContainer(); 354 for (ConnectorEnd targetEnd : targetEnds) { 355 Connector targetConnector = (Connector) targetEnd.eContainer(); 356 if (targetConnector == sourceConnector) { 357 message.setConnector(targetConnector); 361 // now the connector needs to be determined 362 EList<Property> userAttributes = ((Component) msgSourceLifeline.getRepresents().getType()).getAttributes(); 363 EList<Property> targetAttributes = ((Component) msgTargetLifeline.getRepresents().getType()).getAttributes(); 364 365 for( Property userAttribute : userAttributes ) { 366 if( userAttribute instanceof Port ) { 367 EList<ConnectorEnd> userEnds = ((Port) userAttribute).getEnds(); 368 for( ConnectorEnd userEnd : userEnds ) { 369 Connector userConnector = (Connector) userEnd.eContainer(); 370 for( Property targetAttribute : targetAttributes ) { 371 if( targetAttribute instanceof Port ) { 372 EList<ConnectorEnd> targetEnds = ((Port) targetAttribute).getEnds(); 373 for( ConnectorEnd targetEnd : targetEnds ) { 374 Connector targetConnector = (Connector) targetEnd.eContainer(); 375 if( targetConnector==userConnector ) { 376 message.setConnector(targetConnector); 377 } 378 } 379 } 358 380 } 359 381 } 360 382 } 361 383 } 362 384 363 385 sendFragment.setMessage(message); 364 386 recvFragment.setMessage(message); … … 426 448 final Stereotype utpTestCase = (Stereotype) utpProfile.getOwnedMember("TestCase"); 427 449 428 Component testContext = 429 (Component) model.getPackagedElement("TestContext", true, 430 UMLPackage.Literals.COMPONENT, true); 450 Component testContext = fetchTestContext(model); 431 451 432 452 Map<Operation, Double> usageScoreMapUnsorted = new HashMap<>(); … … 509 529 * @return service name 510 530 */ 511 pr ivatestatic String getServiceNameFromEvent(Event event) {531 protected static String getServiceNameFromEvent(Event event) { 512 532 if (event.getType() instanceof SOAPEventType) { 513 533 return ((SOAPEventType) event.getType()).getServiceName(); … … 603 623 604 624 private static Interface getRealizedInterfaceFromComponent(Component comp) { 605 Realization realization = (Realization) comp.getNestedClassifiers().get(0).getRelationships(UMLPackage.Literals.REALIZATION).get(0); 606 return (Interface) realization.getSuppliers().get(0); 607 } 608 625 Interface myInterface = null; 626 for( Property property : comp.getAttributes() ) { 627 if( property instanceof Port ) { 628 Port port = (Port) property; 629 if( !port.isConjugated() ) { 630 if( myInterface==null ) { 631 myInterface = port.getProvideds().get(0); 632 } 633 else if( myInterface!=port.getProvideds().get(0)) { 634 System.err.println("multiple different interfaces found"); 635 } 636 } 637 } 638 } 639 return myInterface; 640 //return ((Port) comp.getAttributes().get(0)).getInterface(); 641 //Realization realization = (Realization) comp.getNestedClassifiers().get(0).getRelationships(UMLPackage.Literals.REALIZATION).get(0); 642 //return (Interface) realization.getSuppliers().get(0); 643 } 644 645 private static Component fetchTestContext(Model model) { 646 final Profile utpProfile = model.getAppliedProfile("utp"); 647 final Stereotype utpTestContext = (Stereotype) utpProfile.getOwnedMember("TestContext"); 648 649 for( Element element : model.getOwnedElements() ) { 650 if( element instanceof Component && element.getApplicableStereotypes().contains(utpTestContext) ) { 651 return (Component) element; 652 } 653 } 654 return null; 655 } 609 656 }
Note: See TracChangeset
for help on using the changeset viewer.