Changeset 1835


Ignore:
Timestamp:
11/27/14 12:44:01 (9 years ago)
Author:
sherbold
Message:
  • updated UMLUtils and UMLUtilsTest to work with a first version of the MIDAS logistics pilot. This also required changes in the service name maps. They now must point to the component for a service, not the interface.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java

    r1763 r1835  
    167167        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 
    168168    } 
     169     
     170    @Test 
     171    public void testCreateInteractionFromEventSequence_2() throws Exception { 
     172        // parse log file 
     173        HTTPLogParser parser = 
     174            new HTTPLogParser(new File(ClassLoader 
     175                .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt") 
     176                .getFile())); 
     177        parser 
     178            .parseFile(new File(ClassLoader 
     179                .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log") 
     180                .getFile())); 
     181        Collection<List<Event>> httpSequences = parser.getSequences(); 
     182 
     183         
     184        Model model = 
     185            ModelUtils.loadModel(ClassLoader 
     186                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 
     187 
     188        for (List<Event> httpSequence : httpSequences) { 
     189            for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
     190                Event event = eventIter.next(); 
     191                if (!(event.getType() instanceof SOAPEventType)) { 
     192                    eventIter.remove(); 
     193                } 
     194            } 
     195 
     196            UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence"); 
     197        } 
     198 
     199        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_2_result.uml"); 
     200         
     201    } 
    169202 
    170203    @Test 
  • trunk/autoquest-plugin-uml-test/src/test/resources/testCalculateUsageScore_1_properties.txt

    r1643 r1835  
    1 /midas/rlus/query/xdw = rlus 
    2 /midas/rlus/update/xdw = rlus 
    3 /midas/rlus/update/cda2report = rlus 
    4 /midas/ixsmq/update/pocdpatient = ixsmq 
    5 /midas/ixsmq/query/pocdpatient = ixsmq 
     1/midas/rlus/query/xdw = rlus_property 
     2/midas/rlus/update/xdw = rlus_property 
     3/midas/rlus/update/cda2report = rlus_property 
     4/midas/ixsmq/update/pocdpatient = ixsmq_property 
     5/midas/ixsmq/query/pocdpatient = ixsmq_property 
  • trunk/autoquest-plugin-uml-test/src/test/resources/testCreateInteractionFromEventSequence_1_properties.txt

    r1625 r1835  
    1 /midas/rlus/query/xdw = rlus 
    2 /midas/rlus/update/xdw = rlus 
    3 /midas/rlus/update/cda2report = rlus 
    4 /midas/ixsmq/update/pocdpatient = ixsmq 
    5 /midas/ixsmq/query/pocdpatient = ixsmq 
     1/midas/rlus/query/xdw = rlus_property 
     2/midas/rlus/update/xdw = rlus_property 
     3/midas/rlus/update/cda2report = rlus_property 
     4/midas/ixsmq/update/pocdpatient = ixsmq_property 
     5/midas/ixsmq/query/pocdpatient = ixsmq_property 
  • trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java

    r1763 r1835  
    3535import org.eclipse.uml2.uml.Connector; 
    3636import org.eclipse.uml2.uml.ConnectorEnd; 
     37import org.eclipse.uml2.uml.Element; 
    3738import org.eclipse.uml2.uml.Interaction; 
    3839import org.eclipse.uml2.uml.InteractionFragment; 
     
    4748import org.eclipse.uml2.uml.Profile; 
    4849import org.eclipse.uml2.uml.Property; 
    49 import org.eclipse.uml2.uml.Realization; 
    5050import org.eclipse.uml2.uml.Region; 
    5151import org.eclipse.uml2.uml.StateMachine; 
     
    272272                                                          String interactionName) 
    273273    { 
    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); 
    279276 
    280277        final Profile utpProfile = model.getAppliedProfile("utp"); 
     
    290287                                                            UMLPackage.Literals.INTERACTION); 
    291288        operation.getMethods().add(interaction); 
    292          
     289 
    293290        // create lifelines 
    294291        Lifeline userLifeline = null; 
    295         List<Port> userPorts = new LinkedList<>(); 
     292        // List<Port> userPorts = new LinkedList<>(); 
    296293        for (Property property : testContext.getAllAttributes()) { 
    297294            if (property.getAppliedStereotypes().contains(utpSUT)) { 
    298                 String serviceName = getRealizedInterfaceFromProperty(property).getName(); 
    299                  
     295                String serviceName = property.getName(); 
    300296                Lifeline targetLifeline = interaction.createLifeline(serviceName); 
    301297                targetLifeline.setRepresents(property); 
    302                 portMap.put(serviceName, 
    303                             (Port) ((Component) property.getType()).getAttribute("p_" + serviceName, null)); 
    304298            } 
    305299            else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 
    306300                userLifeline = interaction.createLifeline(property.getName()); 
    307301                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. 
    316306 
    317307        int i = 0; 
     
    320310                String serviceName = getServiceNameFromEvent(event); 
    321311                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 
    326339                MessageOccurrenceSpecification sendFragment = 
    327340                    (MessageOccurrenceSpecification) interaction 
     
    333346                                        UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 
    334347 
    335                 sendFragment.setCovered(userLifeline); 
    336                 recvFragment.setCovered(targetLifeline); 
     348                sendFragment.setCovered(msgSourceLifeline); 
     349                recvFragment.setCovered(msgTargetLifeline); 
    337350 
    338351                Message message = interaction.createMessage(methodName); 
    339352                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); 
    341354                } 
    342355                message.setSignature(getOperationFromName(targetInterface.getOperations(), 
     
    346359                message.setReceiveEvent(recvFragment); 
    347360 
    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                                } 
    358380                            } 
    359381                        } 
    360382                    } 
    361383                } 
    362  
     384                 
    363385                sendFragment.setMessage(message); 
    364386                recvFragment.setMessage(message); 
     
    426448        final Stereotype utpTestCase = (Stereotype) utpProfile.getOwnedMember("TestCase"); 
    427449 
    428         Component testContext = 
    429             (Component) model.getPackagedElement("TestContext", true, 
    430                                                  UMLPackage.Literals.COMPONENT, true); 
     450        Component testContext = fetchTestContext(model); 
    431451 
    432452        Map<Operation, Double> usageScoreMapUnsorted = new HashMap<>(); 
     
    509529     * @return service name 
    510530     */ 
    511     private static String getServiceNameFromEvent(Event event) { 
     531    protected static String getServiceNameFromEvent(Event event) { 
    512532        if (event.getType() instanceof SOAPEventType) { 
    513533            return ((SOAPEventType) event.getType()).getServiceName(); 
     
    603623     
    604624    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    } 
    609656} 
Note: See TracChangeset for help on using the changeset viewer.