Changeset 1900


Ignore:
Timestamp:
03/06/15 10:24:54 (9 years ago)
Author:
sherbold
Message:
  • updated model validation to report violation counts
  • code documentation
Location:
trunk
Files:
2 edited

Legend:

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

    r1898 r1900  
    4242import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 
    4343import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; 
    44 import de.ugoe.cs.util.console.Console; 
    4544import de.ugoe.cs.util.console.TextConsole; 
    4645 
     
    5857    @BeforeClass 
    5958    public static void setUpBeforeClass() throws Exception { 
    60         Console.getInstance().registerTraceListener(new TextConsole(Level.INFO)); 
     59        new TextConsole(Level.INFO); 
    6160    } 
    6261     
     
    316315                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 
    317316         
    318         UMLUtils.validateModelWithLog(httpSequences, model, null); 
     317        int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 
     318        if( violations==0 ) { 
     319            System.out.println("No problems found."); 
     320        } else { 
     321                System.out.println(violations + " violations found."); 
     322        } 
    319323    } 
    320324     
     
    336340                .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 
    337341         
    338         UMLUtils.validateModelWithLog(httpSequences, model, null); 
     342        int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 
     343        if( violations==0 ) { 
     344            System.out.println("No problems found."); 
     345        } else { 
     346            System.out.println(violations + " violations found."); 
     347        } 
    339348    } 
    340349     
     
    356365                .getSystemResourceAsStream("hl7model_v2.uml")); 
    357366         
    358         UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1"); 
     367        int violations = UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1"); 
     368        if( violations==0 ) { 
     369            System.out.println("No problems found."); 
     370        } else { 
     371            System.out.println(violations + " violations found."); 
     372        } 
    359373    } 
    360374 
  • trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java

    r1898 r1900  
    7777public class UMLUtils { 
    7878 
    79     public static void validateModelWithLog(Collection<List<Event>> sequences, Model model, String testContextName) { 
     79    /** 
     80     * <p> 
     81     * Method for checking if the information in a usage journal can be mapped to the SUT model. In 
     82     * case this is not possible, the violations are reported. 
     83     * </p> 
     84     *  
     85     * @param sequences 
     86     *            sequences of the usage journal 
     87     * @param model 
     88     *            SUT model that is validated 
     89     * @param testContextName 
     90     *            name of the test context to be used; if null, the first test context found is used 
     91     * @return number of violations 
     92     */ 
     93    public static int validateModelWithLog(Collection<List<Event>> sequences, 
     94                                           Model model, 
     95                                           String testContextName) 
     96    { 
    8097        final Profile utpProfile = model.getAppliedProfile("utp"); 
    8198        final Stereotype utpTestComponent = (Stereotype) utpProfile.getOwnedMember("TestComponent"); 
     
    83100        final Stereotype utpTestContext = (Stereotype) utpProfile.getOwnedMember("TestContext"); 
    84101 
     102        int violationCount = 0; 
    85103        Component testContext = fetchTestContext(model, utpTestContext, testContextName); 
    86104        if (testContext == null) { 
    87             if( testContextName==null ) { 
     105            violationCount++; 
     106            if (testContextName == null) { 
    88107                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          
     108 
     109            } 
     110            else { 
     111                Console.traceln(Level.SEVERE, "Could not find TestContext in the model: " + 
     112                    testContextName); 
     113            } 
     114            Console 
     115                .traceln(Level.SEVERE, 
     116                         "Hint: Check if you have applied the TestContext stereotype correctly in the model."); 
     117            Console.traceln(Level.SEVERE, "Aborting"); 
     118            return violationCount; 
     119        } 
     120 
    96121        // Create list of unique methods calls 
    97122        HashMap<String, Set<String>> calledMethods = new HashMap<>(); 
    98         for( List<Event> sequence : sequences ) { 
    99             for( Event event : sequence ) { 
    100                 if( event.getType() instanceof SOAPEventType ) { 
     123        for (List<Event> sequence : sequences) { 
     124            for (Event event : sequence) { 
     125                if (event.getType() instanceof SOAPEventType) { 
    101126                    SOAPEventType eventType = (SOAPEventType) event.getType(); 
    102127                    Set<String> curCalledMethods = calledMethods.get(eventType.getServiceName()); 
    103                     if( curCalledMethods==null ) { 
     128                    if (curCalledMethods == null) { 
    104129                        curCalledMethods = new TreeSet<>(); 
    105130                        calledMethods.put(eventType.getServiceName(), curCalledMethods); 
     
    109134            } 
    110135        } 
    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() + "\": "); 
     136 
     137        Console.traceln(Level.INFO, 
     138                        "Found the following services and operations in the usage data: "); 
     139        for (Entry<String, Set<String>> entry : calledMethods.entrySet()) { 
     140            Console.trace(Level.INFO, "\tService \"" + entry.getKey() + "\": "); 
    115141            Iterator<String> iter = entry.getValue().iterator(); 
    116142            StringBuilder strBld = new StringBuilder(); 
     
    123149            Console.traceln(Level.INFO, strBld.toString()); 
    124150        } 
    125          
     151 
    126152        // fetch all SUTs and TestComponents 
    127153        HashMap<String, Property> properties = new HashMap<>(); 
    128154        for (Property property : testContext.getAllAttributes()) { 
    129155            if (property.getAppliedStereotypes().contains(utpSUT)) { 
    130                 properties.put(property.getName(),property); 
     156                properties.put(property.getName(), property); 
    131157            } 
    132158            else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 
    133                 properties.put(property.getName(),property); 
     159                properties.put(property.getName(), property); 
    134160            } 
    135161        } 
    136162        Console.traceln(Level.INFO, "Found the following services in the TestConfiguration:"); 
    137         for( Entry<String, Property> entry : properties.entrySet() ) { 
     163        for (Entry<String, Property> entry : properties.entrySet()) { 
    138164            Console.traceln(Level.INFO, "\t" + entry.getKey()); 
    139165        } 
    140          
    141         for( Entry<String, Set<String>> entry : calledMethods.entrySet() ) { 
     166 
     167        for (Entry<String, Set<String>> entry : calledMethods.entrySet()) { 
    142168            String serviceName = entry.getKey(); 
    143169            Console.traceln(Level.INFO, "Checking service: " + serviceName); 
    144170            Set<String> methodNames = entry.getValue(); 
    145171            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 { 
     172            if (property == null) { 
     173                violationCount++; 
     174                Console.traceln(Level.SEVERE, "\tCould not find property for service: " + 
     175                    serviceName); 
     176                Console 
     177                    .traceln(Level.SEVERE, 
     178                             "\tHint: Check service name map and/or model if the service is present and spelled correctly."); 
     179                Console 
     180                    .traceln(Level.SEVERE, 
     181                             "\tHint: Check if the SUT/TestComponent stereotype has been applied correctly in this TestContext."); 
     182            } 
     183            else { 
    151184                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();    
     185                if (interfaces.isEmpty()) { 
     186                    violationCount++; 
     187                    Console 
     188                        .traceln(Level.SEVERE, 
     189                                 "\tCould not find any interfaces implementing the property for service: " + 
     190                                     serviceName); 
     191                    Console 
     192                        .traceln(Level.SEVERE, 
     193                                 "\tHint: Check if the property correctly realizes the interfaces in the model."); 
     194                } 
     195                else { 
     196                    Console.traceln(Level.INFO, 
     197                                    "\tFound the following realized interfaces for the service \"" + 
     198                                        serviceName + "\": "); 
     199                    Iterator<Interface> iter = interfaces.iterator(); 
    158200                    while (iter.hasNext()) { 
    159201                        String interfaceName = iter.next().getName(); 
     
    165207                        Console.traceln(Level.INFO, strBld.toString()); 
    166208                    } 
    167                     for( String methodName : methodNames ) { 
    168                         boolean methodFound = true; 
    169                         for( Interface intface : interfaces ) { 
     209                    for (String methodName : methodNames) { 
     210                        boolean methodFound = false; 
     211                        for (Interface intface : interfaces) { 
    170212                            if (getOperationFromName(intface.getOperations(), methodName) != null) { 
    171213                                // interface found 
    172                                 Console.traceln(Level.INFO, "\tMethod " + methodName + " found in interface " + intface.getName() ); 
     214                                Console.traceln(Level.INFO, "\tMethod " + methodName + 
     215                                    " found in interface " + intface.getName()); 
    173216                                methodFound = true; 
    174217                            } 
    175218                        } 
    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"); 
     219                        if (!methodFound) { 
     220                            violationCount++; 
     221                            Console.traceln(Level.SEVERE, "\tCould not find operation: " + 
     222                                methodName); 
     223                            Console 
     224                                .traceln(Level.SEVERE, 
     225                                         "\tHint: check if operation is present and spelled correctly"); 
    179226                        } 
    180227                    } 
     
    182229            } 
    183230        } 
    184          
    185     } 
    186      
     231        return violationCount; 
     232    } 
     233 
    187234    /** 
    188235     * <p> 
     
    412459        // create lifelines 
    413460        Lifeline userLifeline = null; 
    414          
     461 
    415462        for (Property property : testContext.getAllAttributes()) { 
    416463            if (property.getAppliedStereotypes().contains(utpSUT)) { 
     
    420467            } 
    421468            else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 
    422                 if( userLifeline!=null ) { 
    423                     throw new RuntimeException("TestContext must only have one TestComponent for the application of usage-based testing."); 
     469                if (userLifeline != null) { 
     470                    throw new RuntimeException( 
     471                                               "TestContext must only have one TestComponent for the application of usage-based testing."); 
    424472                } 
    425473                userLifeline = interaction.createLifeline(property.getName()); 
     
    427475            } 
    428476        } 
    429         if( userLifeline==null ) { 
     477        if (userLifeline == null) { 
    430478            throw new RuntimeException("No TestComponent found, could not create user lifeline."); 
    431479        } 
    432         if( interaction.getLifelines().size()<2 ) { 
     480        if (interaction.getLifelines().size() < 2) { 
    433481            throw new RuntimeException("Fewer than two lifelines created. No SUT found."); 
    434482        } 
    435          
     483 
    436484        int i = 0; 
    437485        for (Event event : sequence) { 
     
    461509                    msgTargetLifeline = interaction.getLifeline(serviceName); 
    462510                } 
    463                 if( msgSourceLifeline==null ) { 
    464                     throw new RuntimeException("Error creating message: could not determine source lifeline."); 
    465                 } 
    466                 if( msgTargetLifeline==null ) { 
    467                     throw new RuntimeException("Error creating message: could not determine target lifeline."); 
     511                if (msgSourceLifeline == null) { 
     512                    throw new RuntimeException( 
     513                                               "Error creating message: could not determine source lifeline."); 
     514                } 
     515                if (msgTargetLifeline == null) { 
     516                    throw new RuntimeException( 
     517                                               "Error creating message: could not determine target lifeline."); 
    468518                } 
    469519                // determine correct target interface 
     
    484534                if (targetInterface == null) { 
    485535                    StringBuilder errStrBuilder = new StringBuilder(); 
    486                     errStrBuilder.append("Error creating message: operation not found in the implementing interfaces ("); 
     536                    errStrBuilder 
     537                        .append("Error creating message: operation not found in the implementing interfaces ("); 
    487538                    Iterator<Interface> iter = targetInterfaces.iterator(); 
    488539                    while (iter.hasNext()) { 
     
    525576 
    526577                boolean asynch = false; 
    527                 if( calledOperation.getConcurrency()==CallConcurrencyKind.CONCURRENT_LITERAL ) { 
     578                if (calledOperation.getConcurrency() == CallConcurrencyKind.CONCURRENT_LITERAL) { 
    528579                    asynch = true; 
    529580                } 
     
    548599                    replySendFragment.setCovered(msgTargetLifeline); 
    549600                    replyRecvFragment.setCovered(msgSourceLifeline); 
    550                      
    551                     /*BehaviorExecutionSpecification sourceBehaviorExecutionSpecification = 
    552                         (BehaviorExecutionSpecification) interaction 
    553                             .createFragment(":" + methodName + "_sourceBhvExecSpec", 
    554                                             UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
    555                     BehaviorExecutionSpecification targetBehaviorExecutionSpecification = 
    556                         (BehaviorExecutionSpecification) interaction 
    557                             .createFragment(":" + methodName + "_targetBhvExecSpec", 
    558                                             UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
    559  
    560                     sourceBehaviorExecutionSpecification.setStart(callSendFragment); 
    561                     sourceBehaviorExecutionSpecification.setFinish(replyRecvFragment); 
    562                     targetBehaviorExecutionSpecification.setStart(callRecvFragment); 
    563                     targetBehaviorExecutionSpecification.setFinish(replySendFragment);*/ 
     601 
     602                    /* 
     603                     * BehaviorExecutionSpecification sourceBehaviorExecutionSpecification = 
     604                     * (BehaviorExecutionSpecification) interaction .createFragment(":" + methodName 
     605                     * + "_sourceBhvExecSpec", 
     606                     * UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
     607                     * BehaviorExecutionSpecification targetBehaviorExecutionSpecification = 
     608                     * (BehaviorExecutionSpecification) interaction .createFragment(":" + methodName 
     609                     * + "_targetBhvExecSpec", 
     610                     * UMLPackage.Literals.BEHAVIOR_EXECUTION_SPECIFICATION); 
     611                     *  
     612                     * sourceBehaviorExecutionSpecification.setStart(callSendFragment); 
     613                     * sourceBehaviorExecutionSpecification.setFinish(replyRecvFragment); 
     614                     * targetBehaviorExecutionSpecification.setStart(callRecvFragment); 
     615                     * targetBehaviorExecutionSpecification.setFinish(replySendFragment); 
     616                     */ 
    564617 
    565618                    // create reply 
     
    824877                Port port = (Port) property; 
    825878                if (!port.isConjugated()) { 
    826                     interfaces.addAll(port.getProvideds());                   
     879                    interfaces.addAll(port.getProvideds()); 
    827880                } 
    828881            } 
     
    871924    /** 
    872925     * <p> 
    873      * Infers connector between two lifelines.  
    874      * TODO: currently assumes only one connector between two lifelines possible. I need to make sure this assumption is valid. 
     926     * Infers connector between two lifelines. TODO: currently assumes only one connector between 
     927     * two lifelines possible. I need to make sure this assumption is valid. 
    875928     * </p> 
    876929     *  
Note: See TracChangeset for help on using the changeset viewer.