Ignore:
Timestamp:
03/06/15 09:18:02 (9 years ago)
Author:
sherbold
Message:
  • added validation function for models based on observed usage data
  • Interaction generation now automatically decides if a call is SYNCH/ASYNCH based on the concurrency information of the operation that is called
File:
1 edited

Legend:

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

    r1897 r1898  
    1919import java.util.Comparator; 
    2020import java.util.HashMap; 
     21import java.util.HashSet; 
    2122import java.util.Iterator; 
    2223import java.util.LinkedHashMap; 
     
    2526import java.util.Map; 
    2627import java.util.Map.Entry; 
     28import java.util.logging.Level; 
     29import java.util.Set; 
     30import java.util.TreeSet; 
    2731 
    2832import org.eclipse.emf.common.util.EList; 
     
    3034import org.eclipse.uml2.uml.ActivityEdge; 
    3135import org.eclipse.uml2.uml.ActivityNode; 
    32 import org.eclipse.uml2.uml.BehaviorExecutionSpecification; 
     36import org.eclipse.uml2.uml.CallConcurrencyKind; 
    3337import org.eclipse.uml2.uml.CallOperationAction; 
    3438import org.eclipse.uml2.uml.Comment; 
     
    6266import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 
    6367import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; 
     68import de.ugoe.cs.util.console.Console; 
    6469 
    6570/** 
     
    7277public class UMLUtils { 
    7378 
     79    public static void validateModelWithLog(Collection<List<Event>> sequences, Model model, String testContextName) { 
     80        final Profile utpProfile = model.getAppliedProfile("utp"); 
     81        final Stereotype utpTestComponent = (Stereotype) utpProfile.getOwnedMember("TestComponent"); 
     82        final Stereotype utpSUT = (Stereotype) utpProfile.getOwnedMember("SUT"); 
     83        final Stereotype utpTestContext = (Stereotype) utpProfile.getOwnedMember("TestContext"); 
     84 
     85        Component testContext = fetchTestContext(model, utpTestContext, testContextName); 
     86        if (testContext == null) { 
     87            if( testContextName==null ) { 
     88                Console.traceln(Level.SEVERE, "Could not find any TestContext in the model."); 
     89                 
     90            } else { 
     91                Console.traceln(Level.SEVERE, "Could not find TestContext in the model: " + testContextName); 
     92            } 
     93            Console.traceln(Level.SEVERE, "Hint: Check if you have applied the TestContext stereotype correctly in the model."); 
     94        } 
     95         
     96        // Create list of unique methods calls 
     97        HashMap<String, Set<String>> calledMethods = new HashMap<>(); 
     98        for( List<Event> sequence : sequences ) { 
     99            for( Event event : sequence ) { 
     100                if( event.getType() instanceof SOAPEventType ) { 
     101                    SOAPEventType eventType = (SOAPEventType) event.getType(); 
     102                    Set<String> curCalledMethods = calledMethods.get(eventType.getServiceName()); 
     103                    if( curCalledMethods==null ) { 
     104                        curCalledMethods = new TreeSet<>(); 
     105                        calledMethods.put(eventType.getServiceName(), curCalledMethods); 
     106                    } 
     107                    curCalledMethods.add(eventType.getCalledMethod()); 
     108                } 
     109            } 
     110        } 
     111         
     112        Console.traceln(Level.INFO, "Found the following services and operations in the usage data: "); 
     113        for( Entry<String, Set<String>> entry : calledMethods.entrySet() ) { 
     114            Console.traceln(Level.INFO, "\tService \"" + entry.getKey() + "\": "); 
     115            Iterator<String> iter = entry.getValue().iterator(); 
     116            StringBuilder strBld = new StringBuilder(); 
     117            while (iter.hasNext()) { 
     118                strBld.append(iter.next()); 
     119                if (iter.hasNext()) { 
     120                    strBld.append(", "); 
     121                } 
     122            } 
     123            Console.traceln(Level.INFO, strBld.toString()); 
     124        } 
     125         
     126        // fetch all SUTs and TestComponents 
     127        HashMap<String, Property> properties = new HashMap<>(); 
     128        for (Property property : testContext.getAllAttributes()) { 
     129            if (property.getAppliedStereotypes().contains(utpSUT)) { 
     130                properties.put(property.getName(),property); 
     131            } 
     132            else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 
     133                properties.put(property.getName(),property); 
     134            } 
     135        } 
     136        Console.traceln(Level.INFO, "Found the following services in the TestConfiguration:"); 
     137        for( Entry<String, Property> entry : properties.entrySet() ) { 
     138            Console.traceln(Level.INFO, "\t" + entry.getKey()); 
     139        } 
     140         
     141        for( Entry<String, Set<String>> entry : calledMethods.entrySet() ) { 
     142            String serviceName = entry.getKey(); 
     143            Console.traceln(Level.INFO, "Checking service: " + serviceName); 
     144            Set<String> methodNames = entry.getValue(); 
     145            Property property = properties.get(serviceName); 
     146            if( property==null ) { 
     147                Console.traceln(Level.SEVERE, "\tCould not find property for service: " + serviceName); 
     148                Console.traceln(Level.SEVERE, "\tHint: Check service name map and/or model if the service is present and spelled correctly."); 
     149                Console.traceln(Level.SEVERE, "\tHint: Check if the SUT/TestComponent stereotype has been applied correctly in this TestContext."); 
     150            } else { 
     151                Set<Interface> interfaces = getRealizedInterfacesFromProperty(property); 
     152                if( interfaces.isEmpty() ) { 
     153                    Console.traceln(Level.SEVERE, "\tCould not find any interfaces implementing the property for service: " + serviceName); 
     154                    Console.traceln(Level.SEVERE, "\tHint: Check if the property correctly realizes the interfaces in the model."); 
     155                } else { 
     156                    Console.traceln(Level.INFO, "\tFound the following realized interfaces for the service \"" + serviceName + "\": "); 
     157                    Iterator<Interface> iter = interfaces.iterator();    
     158                    while (iter.hasNext()) { 
     159                        String interfaceName = iter.next().getName(); 
     160                        StringBuilder strBld = new StringBuilder(); 
     161                        strBld.append(interfaceName); 
     162                        if (iter.hasNext()) { 
     163                            strBld.append(", "); 
     164                        } 
     165                        Console.traceln(Level.INFO, strBld.toString()); 
     166                    } 
     167                    for( String methodName : methodNames ) { 
     168                        boolean methodFound = true; 
     169                        for( Interface intface : interfaces ) { 
     170                            if (getOperationFromName(intface.getOperations(), methodName) != null) { 
     171                                // interface found 
     172                                Console.traceln(Level.INFO, "\tMethod " + methodName + " found in interface " + intface.getName() ); 
     173                                methodFound = true; 
     174                            } 
     175                        } 
     176                        if( !methodFound ) { 
     177                            Console.traceln(Level.SEVERE, "\tCould not find operation: " + methodName); 
     178                            Console.traceln(Level.SEVERE, "\tHint: check if operation is present and spelled correctly"); 
     179                        } 
     180                    } 
     181                } 
     182            } 
     183        } 
     184         
     185    } 
     186     
    74187    /** 
    75188     * <p> 
     
    355468                } 
    356469                // determine correct target interface 
    357                 List<Interface> targetInterfaces = 
     470                Set<Interface> targetInterfaces = 
    358471                    getRealizedInterfacesFromProperty((Property) msgTargetLifeline.getRepresents()); 
    359472                if (targetInterfaces.isEmpty()) { 
     
    363476                Interface targetInterface = null; 
    364477                for (Interface intface : targetInterfaces) { 
    365                     System.out.println(intface.getOperations()); 
    366478                    if (getOperationFromName(intface.getOperations(), methodName) != null) { 
    367479                        // interface found 
     
    412524                callRecvFragment.setMessage(callMessage); 
    413525 
    414                 // TODO somehow infer if called operation is SYNCH or ASYNCH 
    415                 // possibly requires additional stereotype 
    416526                boolean asynch = false; 
     527                if( calledOperation.getConcurrency()==CallConcurrencyKind.CONCURRENT_LITERAL ) { 
     528                    asynch = true; 
     529                } 
    417530                if (asynch) { 
    418531                    // Create ASYNCH call 
     
    700813    } 
    701814 
    702     private static List<Interface> getRealizedInterfacesFromProperty(Property property) { 
     815    private static Set<Interface> getRealizedInterfacesFromProperty(Property property) { 
    703816        return getRealizedInterfaceFromComponent((Component) property.getType()); 
    704817    } 
    705818 
    706     private static List<Interface> getRealizedInterfaceFromComponent(Component comp) { 
    707         List<Interface> interfaces = new LinkedList<>(); 
     819    private static Set<Interface> getRealizedInterfaceFromComponent(Component comp) { 
     820        Set<Interface> interfaces = new HashSet<>(); 
    708821        // Interface myInterface = null; 
    709822        for (Property property : comp.getAttributes()) { 
Note: See TracChangeset for help on using the changeset viewer.