Index: trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
===================================================================
--- trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java	(revision 1787)
+++ trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java	(revision 1835)
@@ -35,4 +35,5 @@
 import org.eclipse.uml2.uml.Connector;
 import org.eclipse.uml2.uml.ConnectorEnd;
+import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.Interaction;
 import org.eclipse.uml2.uml.InteractionFragment;
@@ -47,5 +48,4 @@
 import org.eclipse.uml2.uml.Profile;
 import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Realization;
 import org.eclipse.uml2.uml.Region;
 import org.eclipse.uml2.uml.StateMachine;
@@ -272,9 +272,6 @@
                                                           String interactionName)
     {
-        Map<String, Port> portMap = new HashMap<>();
-
-        Component testContext =
-            (Component) model.getPackagedElement("TestContext", true,
-                                                 UMLPackage.Literals.COMPONENT, true);
+
+        Component testContext = fetchTestContext(model);
 
         final Profile utpProfile = model.getAppliedProfile("utp");
@@ -290,28 +287,21 @@
                                                             UMLPackage.Literals.INTERACTION);
         operation.getMethods().add(interaction);
-        
+
         // create lifelines
         Lifeline userLifeline = null;
-        List<Port> userPorts = new LinkedList<>();
+        // List<Port> userPorts = new LinkedList<>();
         for (Property property : testContext.getAllAttributes()) {
             if (property.getAppliedStereotypes().contains(utpSUT)) {
-                String serviceName = getRealizedInterfaceFromProperty(property).getName();
-                
+                String serviceName = property.getName();
                 Lifeline targetLifeline = interaction.createLifeline(serviceName);
                 targetLifeline.setRepresents(property);
-                portMap.put(serviceName,
-                            (Port) ((Component) property.getType()).getAttribute("p_" + serviceName, null));
             }
             else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) {
                 userLifeline = interaction.createLifeline(property.getName());
                 userLifeline.setRepresents(property);
-                EList<Property> userAttributes = ((Component) property.getType()).getAttributes();
-                for (Property userAttribute : userAttributes) {
-                    if (userAttribute instanceof Port) {
-                        userPorts.add((Port) userAttribute);
-                    }
-                }
-            } 
-        }
+            }    
+        }
+        
+        // TODO sanity checks for userLifeline!=null, etc.
 
         int i = 0;
@@ -320,8 +310,31 @@
                 String serviceName = getServiceNameFromEvent(event);
                 String methodName = getCalledMethodFromEvent(event);
-
-                Lifeline targetLifeline = interaction.getLifeline(serviceName);
-                Interface targetInterface = getRealizedInterfaceFromProperty((Property) targetLifeline.getRepresents());
-
+                
+                // determine lifelines
+                Lifeline msgTargetLifeline;
+                Lifeline msgSourceLifeline;
+                
+                if( serviceName.equals(userLifeline.getName()) ) {
+                    // message being send to user
+                    // currently we just select the first lifeline that is not the user
+                    // this, obviously, has to be replaced with the real service. 
+                    // however, identification of the source of a message is still an open issue
+                    msgSourceLifeline = null;
+                    for( Lifeline lifeline : interaction.getLifelines() ) {
+                        if(!lifeline.equals(userLifeline)){
+                            msgSourceLifeline = lifeline;
+                            break;
+                        }
+                    }
+                    msgTargetLifeline = userLifeline;
+                } else {
+                    msgSourceLifeline = userLifeline;
+                    msgTargetLifeline = interaction.getLifeline(serviceName);
+                }
+
+                // determine target interface
+                Interface targetInterface = getRealizedInterfaceFromProperty((Property) msgTargetLifeline.getRepresents());
+                
+                // create message
                 MessageOccurrenceSpecification sendFragment =
                     (MessageOccurrenceSpecification) interaction
@@ -333,10 +346,10 @@
                                         UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);
 
-                sendFragment.setCovered(userLifeline);
-                recvFragment.setCovered(targetLifeline);
+                sendFragment.setCovered(msgSourceLifeline);
+                recvFragment.setCovered(msgTargetLifeline);
 
                 Message message = interaction.createMessage(methodName);
                 if (getOperationFromName(targetInterface.getOperations(), methodName) == null) {
-                    System.out.println("operation not found: " + methodName);
+                    System.out.println("operation not found in the " + targetInterface.getName() + " interface: " + methodName);
                 }
                 message.setSignature(getOperationFromName(targetInterface.getOperations(),
@@ -346,19 +359,28 @@
                 message.setReceiveEvent(recvFragment);
 
-                EList<ConnectorEnd> targetEnds = portMap.get(serviceName).getEnds();
-
-                for (Port userPort : userPorts) {
-                    EList<ConnectorEnd> sourceEnds = userPort.getEnds();
-                    for (ConnectorEnd sourceEnd : sourceEnds) {
-                        Connector sourceConnector = (Connector) sourceEnd.eContainer();
-                        for (ConnectorEnd targetEnd : targetEnds) {
-                            Connector targetConnector = (Connector) targetEnd.eContainer();
-                            if (targetConnector == sourceConnector) {
-                                message.setConnector(targetConnector);
+                // now the connector needs to be determined
+                EList<Property> userAttributes = ((Component) msgSourceLifeline.getRepresents().getType()).getAttributes();
+                EList<Property> targetAttributes = ((Component) msgTargetLifeline.getRepresents().getType()).getAttributes();
+                
+                for( Property userAttribute : userAttributes ) {
+                    if( userAttribute instanceof Port ) {
+                        EList<ConnectorEnd> userEnds = ((Port) userAttribute).getEnds();
+                        for( ConnectorEnd userEnd : userEnds ) {
+                            Connector userConnector = (Connector) userEnd.eContainer();
+                            for( Property targetAttribute : targetAttributes ) {
+                                if( targetAttribute instanceof Port ) {
+                                    EList<ConnectorEnd> targetEnds = ((Port) targetAttribute).getEnds();
+                                    for( ConnectorEnd targetEnd : targetEnds ) {
+                                        Connector targetConnector = (Connector) targetEnd.eContainer();
+                                        if( targetConnector==userConnector ) {
+                                            message.setConnector(targetConnector);
+                                        }
+                                    }
+                                }
                             }
                         }
                     }
                 }
-
+                
                 sendFragment.setMessage(message);
                 recvFragment.setMessage(message);
@@ -426,7 +448,5 @@
         final Stereotype utpTestCase = (Stereotype) utpProfile.getOwnedMember("TestCase");
 
-        Component testContext =
-            (Component) model.getPackagedElement("TestContext", true,
-                                                 UMLPackage.Literals.COMPONENT, true);
+        Component testContext = fetchTestContext(model);
 
         Map<Operation, Double> usageScoreMapUnsorted = new HashMap<>();
@@ -509,5 +529,5 @@
      * @return service name
      */
-    private static String getServiceNameFromEvent(Event event) {
+    protected static String getServiceNameFromEvent(Event event) {
         if (event.getType() instanceof SOAPEventType) {
             return ((SOAPEventType) event.getType()).getServiceName();
@@ -603,7 +623,34 @@
     
     private static Interface getRealizedInterfaceFromComponent(Component comp) {
-        Realization realization = (Realization) comp.getNestedClassifiers().get(0).getRelationships(UMLPackage.Literals.REALIZATION).get(0);
-        return (Interface) realization.getSuppliers().get(0);
-    }
-
+        Interface myInterface = null;
+        for( Property property : comp.getAttributes() ) {
+            if( property instanceof Port ) {
+                Port port = (Port) property;
+                if( !port.isConjugated() ) {
+                    if( myInterface==null ) {
+                        myInterface = port.getProvideds().get(0);
+                    } 
+                    else if( myInterface!=port.getProvideds().get(0)) {
+                        System.err.println("multiple different interfaces found");
+                    }
+                }
+            }
+        }
+        return myInterface;
+        //return ((Port) comp.getAttributes().get(0)).getInterface();
+        //Realization realization = (Realization) comp.getNestedClassifiers().get(0).getRelationships(UMLPackage.Literals.REALIZATION).get(0);
+        //return (Interface) realization.getSuppliers().get(0);
+    }
+    
+    private static Component fetchTestContext(Model model) {
+        final Profile utpProfile = model.getAppliedProfile("utp");
+        final Stereotype utpTestContext = (Stereotype) utpProfile.getOwnedMember("TestContext");
+        
+        for( Element element : model.getOwnedElements() ) {
+            if( element instanceof Component && element.getApplicableStereotypes().contains(utpTestContext) ) {
+                return (Component) element;
+            }
+        }
+        return null;
+    }
 }
