Changeset 1898


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
Location:
trunk
Files:
3 edited

Legend:

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

    r1896 r1898  
    2121import java.util.List; 
    2222import java.util.Random; 
     23import java.util.logging.Level; 
    2324 
    2425import org.apache.commons.lang.SerializationUtils; 
     
    2930import org.eclipse.uml2.uml.UMLPackage; 
    3031import org.junit.After; 
     32import org.junit.BeforeClass; 
    3133import org.junit.Test; 
    3234 
     
    4042import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 
    4143import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; 
     44import de.ugoe.cs.util.console.Console; 
     45import de.ugoe.cs.util.console.TextConsole; 
    4246 
    4347/** 
     
    5256    private final static String OUTPUT_DIR = "target/tmp/test-outputs/"; 
    5357 
    54     /** 
    55     * 
    56     */ 
     58    @BeforeClass 
     59    public static void setUpBeforeClass() throws Exception { 
     60        Console.getInstance().registerTraceListener(new TextConsole(Level.INFO)); 
     61    } 
     62     
    5763    @After 
    5864    public void tearDown() throws Exception { 
     
    181187        Collection<List<Event>> httpSequences = parser.getSequences(); 
    182188 
    183          
    184189        Model model = 
    185190            ModelUtils.loadModel(ClassLoader 
     
    197202        } 
    198203 
    199         ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_2_result.uml"); 
    200          
     204        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 
    201205    } 
    202206     
     
    294298        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml"); 
    295299    } 
     300     
     301    @Test 
     302    public void testValidateModelWithLog_1() throws Exception { 
     303        HTTPLogParser parser = 
     304                new HTTPLogParser(new File(ClassLoader 
     305                    .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 
     306                    .getFile())); 
     307        parser 
     308            .parseFile(new File(ClassLoader 
     309                .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
     310                .getFile())); 
     311        Collection<List<Event>> httpSequences = parser.getSequences(); 
     312 
     313         
     314        Model model = 
     315            ModelUtils.loadModel(ClassLoader 
     316                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 
     317         
     318        UMLUtils.validateModelWithLog(httpSequences, model, null); 
     319    } 
     320     
     321    @Test 
     322    public void testValidateModelWithLog_2() throws Exception { 
     323        HTTPLogParser parser = 
     324                new HTTPLogParser(new File(ClassLoader 
     325                    .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt") 
     326                    .getFile())); 
     327        parser 
     328            .parseFile(new File(ClassLoader 
     329                .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log") 
     330                .getFile())); 
     331        Collection<List<Event>> httpSequences = parser.getSequences(); 
     332 
     333         
     334        Model model = 
     335            ModelUtils.loadModel(ClassLoader 
     336                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 
     337         
     338        UMLUtils.validateModelWithLog(httpSequences, model, null); 
     339    } 
     340     
     341    @Test 
     342    public void testValidateModelWithLog_HL7_v2() throws Exception { 
     343        HTTPLogParser parser = 
     344                new HTTPLogParser(new File(ClassLoader 
     345                    .getSystemResource("hl7_servicenamemap.txt") 
     346                    .getFile())); 
     347        parser 
     348            .parseFile(new File(ClassLoader 
     349                .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
     350                .getFile())); 
     351        Collection<List<Event>> httpSequences = parser.getSequences(); 
     352 
     353         
     354        Model model = 
     355            ModelUtils.loadModel(ClassLoader 
     356                .getSystemResourceAsStream("hl7model_v2.uml")); 
     357         
     358        UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1"); 
     359    } 
    296360 
    297361    private void deleteFiles(File file) { 
  • trunk/autoquest-plugin-uml-test/src/test/resources/hl7_servicenamemap.txt

    r1896 r1898  
    22/midas/rlus/update/xdw = rlusService 
    33/midas/rlus/update/cda2report = rlusService 
    4 /midas/ixsmq/update/pocdpatient = ixsmq_property 
    5 /midas/ixsmq/query/pocdpatient = ixsmq_property 
     4/midas/ixsmq/update/pocdpatient = ixsService 
     5/midas/ixsmq/query/pocdpatient = ixsService 
  • 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.