Ignore:
Timestamp:
03/18/15 16:02:08 (9 years ago)
Author:
sherbold
Message:
  • refactored tests
File:
1 edited

Legend:

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

    r1926 r1927  
    1616 
    1717import java.io.File; 
     18import java.io.FileInputStream; 
    1819import java.util.Collection; 
     20import java.util.HashSet; 
    1921import java.util.Iterator; 
    2022import java.util.LinkedList; 
    2123import java.util.List; 
     24import java.util.Properties; 
    2225import java.util.Random; 
     26import java.util.Set; 
    2327import java.util.logging.Level; 
    2428 
    25 import static org.junit.Assert.*; 
     29//import static org.junit.Assert.*; 
    2630 
    2731import org.apache.commons.lang.SerializationUtils; 
     
    5458 
    5559    private final static String OUTPUT_DIR = "target/tmp/test-outputs/"; 
     60     
     61    // for RLUS 
     62    private final static TestData deda_1 = new TestData("deda_rlus_properties.prop", 
     63                                                      "deda_usagejournal.log", 
     64                                                      "deda_rlus_usageprofile.dat", 
     65                                                      "deda_model.uml", 
     66                                                      "deda_rlus_model_testsuite.uml", 
     67                                                      "deda_rlus_model_scheduling.uml"); 
     68 
     69    // for IXS 
     70    private final static TestData deda_2 = new TestData("deda_ixs_properties.prop", 
     71                                                           "deda_usagejournal.log", 
     72                                                           "deda_ixs_usageprofile.dat", 
     73                                                           "deda_model.uml", 
     74                                                           "deda_ixs_model_testsuite.uml", 
     75                                                           "deda_ixs_model_scheduling.uml"); 
     76 
     77    private final static TestData ita_1 = new TestData("ita_properties.prop", "ita_usagejournal.log", 
     78                                                     "ita_usageprofile.dat", "ita_model.uml", 
     79                                                     "ita_model_testsuite.uml", 
     80                                                     "ita_model_scheduling.uml"); 
     81     
     82    private static class TestData { 
     83        public final String propertiesFile; 
     84        public final String usageJournalFile; 
     85        public final String usageProfileFile; 
     86        public final String dslModelFile; 
     87        public final String testSuiteFile; 
     88        public final String schedulingFile; 
     89 
     90        public TestData(String propertiesFile, 
     91                String usageJournalFile, 
     92                String usageProfileFile, 
     93                String dslModelFile, 
     94                String testSuiteFile, 
     95                String schedulingFile) 
     96        { 
     97            this.propertiesFile = propertiesFile; 
     98            this.usageJournalFile = usageJournalFile; 
     99            this.usageProfileFile = usageProfileFile; 
     100            this.dslModelFile = dslModelFile; 
     101            this.testSuiteFile = testSuiteFile; 
     102            this.schedulingFile = schedulingFile; 
     103             
     104        } 
     105 
     106        @Override 
     107        public String toString() { 
     108            StringBuilder strBld = new StringBuilder(); 
     109            strBld.append("Properties    " + propertiesFile + "\n"); 
     110            strBld.append("Usage Journal " + usageJournalFile + "\n"); 
     111            strBld.append("Usage Profile " + usageProfileFile + "\n"); 
     112            strBld.append("DSL Model     " + dslModelFile + "\n"); 
     113            strBld.append("Test Suite    " + testSuiteFile + "\n"); 
     114            strBld.append("Scheduling    " + schedulingFile + "\n"); 
     115            return strBld.toString(); 
     116        } 
     117    } 
    56118 
    57119    @BeforeClass 
    58120    public static void setUpBeforeClass() throws Exception { 
    59         new TextConsole(Level.INFO); 
     121        new TextConsole(Level.FINE); 
    60122    } 
    61123 
     
    66128 
    67129    @Test(expected = java.lang.RuntimeException.class) 
    68     public void testCreateUMLTransitionSequence_1() throws Exception { 
    69         // parse log file 
    70         HTTPLogParser parser = 
    71             new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt") 
    72                 .getFile())); 
    73         parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log") 
    74             .getFile())); 
    75         Collection<List<Event>> httpSequences = parser.getSequences(); 
    76  
     130    public void testCreateUMLTransitionSequence_ITA_1() throws Exception { 
     131        TestData testdata = ita_1; 
     132         
     133        Properties properties = loadProperties(testdata); 
     134        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
    77135        Model model = 
    78             ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml")); 
     136            ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile)); 
    79137 
    80138        StateMachine stateMachine = 
     
    86144         
    87145        // remove everything but transport from sequences 
    88         for (List<Event> httpSequence : httpSequences) { 
    89             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    90                 Event event = eventIter.next(); 
    91                 if (!(event.getType() instanceof SOAPEventType)) { 
    92                     eventIter.remove(); 
    93                 } 
    94                 else { 
    95                     SOAPEventType eventType = (SOAPEventType) event.getType(); 
    96                     if (!"TransportService".equals(eventType.getServiceName())) { 
    97                         eventIter.remove(); 
    98                     } 
    99                 } 
    100             } 
    101             umlSequences.add(UMLUtils.createUMLTransitionSequence(httpSequence, stateMachine)); 
    102         } 
    103     } 
    104  
    105     @Test 
    106     public void testConvertStateMachineToUsageProfile_1() throws Exception { 
    107         HTTPLogParser parser = 
    108             new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt") 
    109                 .getFile())); 
    110         parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log") 
    111             .getFile())); 
    112         Collection<List<Event>> httpSequences = parser.getSequences(); 
    113  
    114         Model model = 
    115             ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml")); 
    116  
    117         // remove everything but transport from sequences 
    118         for (List<Event> httpSequence : httpSequences) { 
    119             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    120                 Event event = eventIter.next(); 
    121                 if (!(event.getType() instanceof SOAPEventType)) { 
    122                     eventIter.remove(); 
    123                 } 
    124                 else { 
    125                     SOAPEventType eventType = (SOAPEventType) event.getType(); 
    126                     if (!"TransportService".equals(eventType.getServiceName())) { 
    127                         eventIter.remove(); 
    128                     } 
    129                 } 
    130             } 
    131         } 
    132  
    133         StateMachine stateMachine = 
    134             (StateMachine) model.getPackagedElement("StateMachineTransportService", true, 
    135                                                     UMLPackage.Literals.STATE_MACHINE, true); 
    136  
    137         UMLUtils.convertStateMachineToUsageProfile(httpSequences, stateMachine); 
    138  
    139         ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml"); 
    140     } 
    141  
    142     @Test 
    143     public void testCreateInteractionFromEventSequence_1() throws Exception { 
    144         // parse log file 
    145         HTTPLogParser parser = 
    146             new HTTPLogParser(new File(ClassLoader 
    147                 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 
    148                 .getFile())); 
    149         parser 
    150             .parseFile(new File(ClassLoader 
    151                 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
    152                 .getFile())); 
    153         Collection<List<Event>> httpSequences = parser.getSequences(); 
    154  
    155         Model model = 
    156             ModelUtils.loadModel(ClassLoader 
    157                 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 
    158  
    159         for (List<Event> httpSequence : httpSequences) { 
    160             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    161                 Event event = eventIter.next(); 
    162                 if (!(event.getType() instanceof SOAPEventType)) { 
    163                     eventIter.remove(); 
    164                 } 
    165             } 
    166  
    167             UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence", null); 
    168         } 
    169  
    170         ModelUtils.writeModelToFile(model, OUTPUT_DIR + 
    171             "testCreateInteractionFromEventSequence_1_result.uml"); 
    172     } 
    173  
    174     @Test 
    175     public void testCreateInteractionFromEventSequence_2() throws Exception { 
    176         // parse log file 
    177         HTTPLogParser parser = 
    178             new HTTPLogParser(new File(ClassLoader 
    179                 .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt") 
    180                 .getFile())); 
    181         parser 
    182             .parseFile(new File(ClassLoader 
    183                 .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log") 
    184                 .getFile())); 
    185         Collection<List<Event>> httpSequences = parser.getSequences(); 
    186  
    187         Model model = 
    188             ModelUtils.loadModel(ClassLoader 
    189                 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 
    190  
    191         for (List<Event> httpSequence : httpSequences) { 
    192             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    193                 Event event = eventIter.next(); 
    194                 if (!(event.getType() instanceof SOAPEventType)) { 
    195                     eventIter.remove(); 
    196                 } 
    197             } 
    198  
    199             UMLUtils.createInteractionFromEventSequence(httpSequence, model, "testSequence", null); 
    200         } 
    201  
    202         ModelUtils.writeModelToFile(model, OUTPUT_DIR + 
    203             "testCreateInteractionFromEventSequence_1_result.uml"); 
    204     } 
    205  
    206     @Test 
    207     public void testCalculateUsageScore_1() throws Exception { 
    208         // parse log file 
    209         HTTPLogParser parser = 
    210             new HTTPLogParser(new File(ClassLoader 
    211                 .getSystemResource("testCalculateUsageScore_1_properties.txt").getFile())); 
    212         parser.parseFile(new File(ClassLoader 
    213             .getSystemResource("testCalculateUsageScore_1_usagedata.log").getFile())); 
    214         Collection<List<Event>> httpSequences = parser.getSequences(); 
    215  
    216         Model model = 
    217             ModelUtils.loadModel(ClassLoader 
    218                 .getSystemResourceAsStream("testCalculateUsageScore_1_model.uml")); 
    219  
    220         Collection<List<Event>> simpleSOAPSequences = new LinkedList<>(); 
    221         for (List<Event> httpSequence : httpSequences) { 
    222             simpleSOAPSequences.add(SOAPUtils.convertToSimpleSOAPEvent(httpSequence, true)); 
    223         } 
    224  
    225         FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1)); 
    226         usageProfile.train(simpleSOAPSequences); 
    227  
    228         Collection<List<Event>> genSeqs = 
    229             (new RandomWalkGenerator(10, 1, 100, true, 500)).generateTestSuite(usageProfile); 
    230  
    231         int i = 1; 
    232         int[] lengths = new int[genSeqs.size()]; 
    233         for (List<Event> seq : genSeqs) { 
    234             UMLUtils.createInteractionFromEventSequence(seq, model, "seq_" + i, null); 
    235             lengths[i - 1] = seq.size(); 
    236             i++; 
    237         } 
    238         for (int j = 0; j < genSeqs.size(); j++) { 
    239             Interaction interaction = 
    240                 (Interaction) model.getPackagedElement("seq_" + j, true, 
    241                                                        UMLPackage.Literals.INTERACTION, true); 
    242             double usageScore = UMLUtils.calculateUsageScore(interaction, usageProfile); 
    243             System.out.format("usage score %02d: %.2f \t %d\n", j + 1, usageScore, lengths[j]); 
    244         } 
    245     } 
    246  
    247     @Test 
    248     public void testCreateScheduling_1() throws Exception { 
    249         Model model = 
    250             ModelUtils.loadModel(ClassLoader 
    251                 .getSystemResourceAsStream("testCreateScheduling_1_testsuite.uml")); 
    252  
    253         IStochasticProcess usageProfile = 
    254             (IStochasticProcess) SerializationUtils.deserialize(ClassLoader 
    255                 .getSystemResourceAsStream("testCreateScheduling_1_usageprofile.dat")); 
    256  
    257         UMLUtils.createScheduling(model, usageProfile, null); 
    258  
    259         ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml"); 
    260     } 
    261  
    262     @Test 
    263     public void testValidateModelWithLog_1() throws Exception { 
    264         HTTPLogParser parser = 
    265             new HTTPLogParser(new File(ClassLoader 
    266                 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 
    267                 .getFile())); 
    268         parser 
    269             .parseFile(new File(ClassLoader 
    270                 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
    271                 .getFile())); 
    272         Collection<List<Event>> httpSequences = parser.getSequences(); 
    273  
    274         for (List<Event> httpSequence : httpSequences) { 
    275             SOAPUtils.removeNonSOAPEvents(httpSequence); 
    276         } 
    277          
    278         Model model = 
    279             ModelUtils.loadModel(ClassLoader 
    280                 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 
    281  
    282         int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 
    283         if (violations == 0) { 
    284             System.out.println("No problems found."); 
    285         } 
    286         else { 
    287             System.out.println(violations + " violations found."); 
    288         } 
    289     } 
    290  
    291     @Test 
    292     public void testValidateModelWithLog_2() throws Exception { 
    293         HTTPLogParser parser = 
    294             new HTTPLogParser(new File(ClassLoader 
    295                 .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt") 
    296                 .getFile())); 
    297         parser 
    298             .parseFile(new File(ClassLoader 
    299                 .getSystemResource("testCreateInteractionFromEventSequence_2_usagedata.log") 
    300                 .getFile())); 
    301         Collection<List<Event>> httpSequences = parser.getSequences(); 
    302  
    303         for (List<Event> httpSequence : httpSequences) { 
    304             SOAPUtils.removeNonSOAPEvents(httpSequence); 
    305         } 
    306          
    307         Model model = 
    308             ModelUtils.loadModel(ClassLoader 
    309                 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 
    310  
    311         int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 
    312         if (violations == 0) { 
    313             System.out.println("No problems found."); 
    314         } 
    315         else { 
    316             System.out.println(violations + " violations found."); 
    317         } 
    318     } 
    319  
    320     @Test 
    321     public void testValidateModelWithLog_HL7_RLUS_v3() throws Exception { 
    322         HTTPLogParser parser = 
    323             new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_servicenamemap.txt") 
    324                 .getFile())); 
    325         parser 
    326             .parseFile(new File(ClassLoader 
    327                 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
    328                 .getFile())); 
    329         Collection<List<Event>> httpSequences = parser.getSequences(); 
    330  
    331         for (List<Event> httpSequence : httpSequences) { 
    332             SOAPUtils.removeNonSOAPEvents(httpSequence); 
    333         } 
    334          
    335         Model model = 
    336             ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml")); 
    337  
    338         int violations = UMLUtils.validateModelWithLog(httpSequences, model, "RLUSTestSuite_1"); 
    339         if (violations == 0) { 
    340             System.out.println("No problems found."); 
    341         } 
    342         else { 
    343             System.out.println(violations + " violations found."); 
    344         } 
    345  
    346         // remove everything but rlusService from sequences 
    347         for (List<Event> httpSequence : httpSequences) { 
    348             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    349                 Event event = eventIter.next(); 
    350                 SOAPEventType eventType = (SOAPEventType) event.getType(); 
    351                 if (!"rlusService".equals(eventType.getServiceName()) ) { 
    352                     eventIter.remove(); 
    353                 } 
    354             } 
    355  
    356             UMLUtils.createInteractionFromEventSequence(httpSequence, model, "rlustest1", 
    357                                                         "RLUSTestSuite_1"); 
    358             UMLUtils.createInteractionFromEventSequence(SOAPUtils.convertToSimpleSOAPEvent(httpSequence, true), model, "rlustest2", 
    359                     "RLUSTestSuite_1"); 
    360         } 
    361  
    362         ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml"); 
    363     } 
    364  
    365     @Test 
    366     public void testValidateModelWithLog_HL7_IXS_v3() throws Exception { 
    367         HTTPLogParser parser = 
    368             new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_ixs_servicenamemap.txt") 
    369                 .getFile())); 
    370         parser 
    371             .parseFile(new File(ClassLoader 
    372                 .getSystemResource("testCreateInteractionFromEventSequence_1_usagedata.log") 
    373                 .getFile())); 
    374         Collection<List<Event>> httpSequences = parser.getSequences(); 
    375  
    376         for (List<Event> httpSequence : httpSequences) { 
    377             SOAPUtils.removeNonSOAPEvents(httpSequence); 
    378         } 
    379          
    380         Model model = 
    381             ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml")); 
    382  
    383         int violations = UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1"); 
    384         if (violations == 0) { 
    385             System.out.println("No problems found."); 
    386         } 
    387         else { 
    388             System.out.println(violations + " violations found."); 
    389         } 
    390  
    391         // remove everything but rlusService from sequences 
    392         for (List<Event> httpSequence : httpSequences) { 
    393             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
    394                 Event event = eventIter.next(); 
    395                 SOAPEventType eventType = (SOAPEventType) event.getType(); 
    396                 if (!"ixsService".equals(eventType.getServiceName())) { 
    397                     eventIter.remove(); 
    398                 } 
    399             } 
    400  
    401             UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", 
    402                                                         "IXSTestSuite_1"); 
    403         } 
    404  
    405         ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml"); 
    406     } 
    407  
    408     @Test 
    409     public void testValidateModelWithLog_ITA_v2() throws Exception { 
    410         HTTPLogParser parser = 
    411             new HTTPLogParser(new File(ClassLoader.getSystemResource("ita_v2_servicenamemap.txt") 
    412                 .getFile())); 
    413         parser.parseFile(new File(ClassLoader.getSystemResource("ita_usagejournal_v2_2.log") 
    414             .getFile())); 
    415         Collection<List<Event>> httpSequences = parser.getSequences(); 
    416          
    417         for (List<Event> httpSequence : httpSequences) { 
    418             SOAPUtils.removeNonSOAPEvents(httpSequence); 
    419         } 
    420  
    421         Model model = 
    422             ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml")); 
    423  
    424         int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 
    425         if (violations == 0) { 
    426             System.out.println("No problems found."); 
    427         } 
    428         else { 
    429             System.out.println(violations + " violations found."); 
    430         } 
    431  
    432         // remove everything but transport from sequences 
    433         for (List<Event> httpSequence : httpSequences) { 
    434             for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 
     146        for (List<Event> sequence : sequences) { 
     147            for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
    435148                Event event = eventIter.next(); 
    436149                SOAPEventType eventType = (SOAPEventType) event.getType(); 
     
    439152                } 
    440153            } 
    441  
    442             UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", 
    443                                                         "LogisticsTestSuite"); 
    444         } 
     154            umlSequences.add(UMLUtils.createUMLTransitionSequence(sequence, stateMachine)); 
     155        } 
     156    } 
     157 
     158    @Test 
     159    public void testConvertStateMachineToUsageProfile__ITA_1() throws Exception { 
     160        TestData testdata = ita_1; 
     161         
     162        Properties properties = loadProperties(testdata); 
     163        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
     164 
     165        Model model = 
     166            ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile)); 
     167 
     168        // remove everything but transport from sequences 
     169        for (List<Event> sequence : sequences) { 
     170            for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
     171                Event event = eventIter.next(); 
     172                SOAPEventType eventType = (SOAPEventType) event.getType(); 
     173                if (!"TransportService".equals(eventType.getServiceName())) { 
     174                    eventIter.remove(); 
     175                } 
     176            } 
     177        } 
     178 
     179        StateMachine stateMachine = 
     180            (StateMachine) model.getPackagedElement("StateMachineTransportService", true, 
     181                                                    UMLPackage.Literals.STATE_MACHINE, true); 
     182 
     183        UMLUtils.convertStateMachineToUsageProfile(sequences, stateMachine); 
    445184 
    446185        ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml"); 
    447  
    448     } 
    449  
     186    } 
     187 
     188    @Test 
     189    public void testCreateInteractionFromEventSequence_DEDA_1() throws Exception { 
     190        createInteractionFromEventSequenceWorkflow(deda_1); 
     191    } 
     192     
     193    @Test 
     194    public void testCreateInteractionFromEventSequence_DEDA_2() throws Exception { 
     195        createInteractionFromEventSequenceWorkflow(deda_2); 
     196    } 
     197     
     198    @Test 
     199    public void testCreateInteractionFromEventSequence_ITA_1() throws Exception { 
     200        createInteractionFromEventSequenceWorkflow(ita_1); 
     201    } 
     202 
     203    @Test 
     204    public void testCalculateUsageScore_DEDA_1() throws Exception { 
     205        calculateUsageScoreWorkflow(deda_1); 
     206    } 
     207     
     208    @Test 
     209    public void testCalculateUsageScore_DEDA_2() throws Exception { 
     210        calculateUsageScoreWorkflow(deda_2); 
     211    } 
     212 
     213     
     214    @Test 
     215    public void testCalculateUsageScore_ITA_1() throws Exception { 
     216        calculateUsageScoreWorkflow(ita_1); 
     217    } 
     218 
     219    @Test 
     220    public void testCreateScheduling_DEDA_1() throws Exception { 
     221        createSchedulingWorkflow(deda_1); 
     222    } 
     223     
     224    @Test 
     225    public void testCreateScheduling_DEDA_2() throws Exception { 
     226        createSchedulingWorkflow(deda_2); 
     227    } 
     228     
     229    @Test 
     230    public void testCreateScheduling_ITA() throws Exception { 
     231        createSchedulingWorkflow(ita_1); 
     232    } 
     233 
     234    @Test 
     235    public void testValidateModelWithLog_DEDA_1() throws Exception { 
     236        validateModelWithLogWorkflow(deda_1); 
     237    } 
     238     
     239 
     240    @Test 
     241    public void testValidateModelWithLog_DEDA_2() throws Exception { 
     242        validateModelWithLogWorkflow(deda_2); 
     243    } 
     244 
     245    @Test 
     246    public void testValidateModelWithLog_ITA_1() throws Exception { 
     247        validateModelWithLogWorkflow(ita_1); 
     248    } 
     249     
     250    private void validateModelWithLogWorkflow(TestData testdata) throws Exception { 
     251        Properties properties = loadProperties(testdata); 
     252        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
     253        Model model = ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile)); 
     254         
     255        // run validation 
     256        int violations = UMLUtils.validateModelWithLog(sequences, model, properties.getProperty("test.context")); 
     257        if (violations == 0) { 
     258            System.out.println("No problems found."); 
     259        } 
     260        else { 
     261            System.out.println(violations + " violations found."); 
     262        } 
     263    } 
     264     
     265    private void createInteractionFromEventSequenceWorkflow(TestData testdata) throws Exception { 
     266        Properties properties = loadProperties(testdata); 
     267        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
     268        Model model = ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile)); 
     269         
     270        // create a test case for each observed sequence 
     271        int i=0; 
     272        for( List<Event> sequence : sequences ) { 
     273            UMLUtils.createInteractionFromEventSequence(sequence, model, properties.getProperty("testcases.prefix")+"_"+i, 
     274                    properties.getProperty("test.context")); 
     275            i++; 
     276        } 
     277    } 
     278     
     279    private void calculateUsageScoreWorkflow(TestData testdata) throws Exception { 
     280        Properties properties = loadProperties(testdata); 
     281        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
     282        Model model = 
     283            ModelUtils.loadModel(ClassLoader 
     284                .getSystemResourceAsStream(testdata.dslModelFile)); 
     285        IStochasticProcess usageProfile = createUsageProfile(sequences); 
     286        Collection<List<Event>> generatedSequences = createRandomSequences(usageProfile, properties); 
     287         
     288        int i = 1; 
     289        int[] lengths = new int[generatedSequences.size()]; 
     290        for (List<Event> sequence : generatedSequences) { 
     291            UMLUtils.createInteractionFromEventSequence(sequence, model, properties.getProperty("testcases.prefix")+"_"+i, 
     292                                                        properties.getProperty("test.context")); 
     293            lengths[i - 1] = sequence.size(); 
     294            i++; 
     295        } 
     296        for (int j = 0; j < generatedSequences.size(); j++) { 
     297            Interaction interaction = 
     298                (Interaction) model.getPackagedElement(properties.getProperty("testcases.prefix") + j, true, 
     299                                                       UMLPackage.Literals.INTERACTION, true); 
     300            double usageScore = UMLUtils.calculateUsageScore(interaction, usageProfile); 
     301            System.out.format("usage score %02d: %.2f \t %d\n", j + 1, usageScore, lengths[j]); 
     302        } 
     303    } 
     304     
     305    private void createSchedulingWorkflow(TestData testdata) throws Exception { 
     306        Properties properties = loadProperties(testdata); 
     307        Collection<List<Event>> sequences = loadAndPreprocessUsageJournal(testdata, properties); 
     308        Model model = ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream(testdata.dslModelFile)); 
     309        IStochasticProcess usageProfile = createUsageProfile(sequences); 
     310        Collection<List<Event>> generatedSequences = createRandomSequences(usageProfile, properties); 
     311        int i = 1; 
     312        for (List<Event> sequence : generatedSequences) { 
     313            UMLUtils.createInteractionFromEventSequence(sequence, model, properties.getProperty("testcases.prefix")+"_"+i, 
     314                                                        properties.getProperty("test.context")); 
     315            i++; 
     316        } 
     317         
     318        UMLUtils.createScheduling(model, usageProfile, null); 
     319 
     320        //ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml"); 
     321    } 
     322     
     323    private Properties loadProperties(TestData testdata) throws Exception { 
     324        Properties properties = new Properties(); 
     325        properties.load(new FileInputStream(ClassLoader.getSystemResource(testdata.propertiesFile).getFile())); 
     326        return properties; 
     327    } 
     328     
     329    private Collection<List<Event>> loadAndPreprocessUsageJournal(TestData testdata, Properties properties) throws Exception { 
     330        // load usage journal 
     331        HTTPLogParser parser = 
     332            new HTTPLogParser(new File(ClassLoader.getSystemResource(testdata.propertiesFile) 
     333                .getFile())); 
     334        parser 
     335            .parseFile(new File(ClassLoader 
     336                .getSystemResource(testdata.usageJournalFile) 
     337                .getFile())); 
     338        Collection<List<Event>> sequences = parser.getSequences(); 
     339 
     340        // remove non SOAP events 
     341        for (List<Event> sequence : sequences) { 
     342            SOAPUtils.removeNonSOAPEvents(sequence); 
     343        } 
     344         
     345        // remove calls to ingored services 
     346        Set<String> ignoredServices = new HashSet<>(); 
     347        String ignoredServicesString = properties.getProperty("test.ignored.services"); 
     348        if( ignoredServicesString!=null ) { 
     349            for( String service : ignoredServicesString.split(",") ) { 
     350                ignoredServices.add(service.trim()); 
     351            } 
     352        } 
     353         
     354        for (List<Event> sequence : sequences) { 
     355            for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
     356                Event event = eventIter.next(); 
     357                SOAPEventType eventType = (SOAPEventType) event.getType(); 
     358                if (ignoredServices.contains(eventType.getServiceName())) { 
     359                    eventIter.remove(); 
     360                } 
     361            } 
     362        } 
     363        return sequences; 
     364    } 
     365     
     366    private IStochasticProcess createUsageProfile(Collection<List<Event>> sequences) throws Exception { 
     367        Collection<List<Event>> simpleSOAPSequences = new LinkedList<>(); 
     368        for (List<Event> sequence : sequences) { 
     369            simpleSOAPSequences.add(SOAPUtils.convertToSimpleSOAPEvent(sequence, true)); 
     370        } 
     371 
     372        FirstOrderMarkovModel usageProfile = new FirstOrderMarkovModel(new Random(1)); 
     373        usageProfile.train(simpleSOAPSequences); 
     374        return usageProfile; 
     375    } 
     376     
     377    private Collection<List<Event>> createRandomSequences(IStochasticProcess usageProfile, Properties properties) throws Exception { 
     378        int numberOfTestCases = Integer.parseInt(properties.getProperty("testcases.number")); 
     379        int testCaseMinLength = Integer.parseInt(properties.getProperty("testcases.minlenth", "1")); 
     380        int testCaseMaxLength = Integer.parseInt(properties.getProperty("testcases.maxlenth", "100")); 
     381        int maxIter = numberOfTestCases * 100; 
     382        RandomWalkGenerator testGenerator = new RandomWalkGenerator(numberOfTestCases, testCaseMinLength, testCaseMaxLength, true, maxIter); 
     383        return testGenerator.generateTestSuite(usageProfile); 
     384    } 
     385     
    450386    private void deleteFiles(File file) { 
    451387        if (file.exists()) { 
Note: See TracChangeset for help on using the changeset viewer.