Changeset 1926 for trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe
- Timestamp:
- 03/18/15 10:05:36 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java
r1917 r1926 23 23 import java.util.logging.Level; 24 24 25 import static org.junit.Assert.*; 26 25 27 import org.apache.commons.lang.SerializationUtils; 26 28 import org.eclipse.uml2.uml.Interaction; 27 29 import org.eclipse.uml2.uml.Model; 28 30 import org.eclipse.uml2.uml.StateMachine; 29 import org.eclipse.uml2.uml.Transition;30 31 import org.eclipse.uml2.uml.UMLPackage; 31 32 import org.junit.After; … … 36 37 import de.ugoe.cs.autoquest.eventcore.Event; 37 38 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 38 import de.ugoe.cs.autoquest.plugin.http. HTTPUtils;39 import de.ugoe.cs.autoquest.plugin.http.SOAPUtils; 39 40 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 40 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType;41 41 import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator; 42 42 import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; … … 59 59 new TextConsole(Level.INFO); 60 60 } 61 61 62 62 @After 63 63 public void tearDown() throws Exception { … … 68 68 public void testCreateUMLTransitionSequence_1() throws Exception { 69 69 // parse log file 70 HTTPLogParser parser = new HTTPLogParser(); 71 parser.parseFile(new File(ClassLoader.getSystemResource("createSequence_1_usagedata.log") 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") 72 74 .getFile())); 73 75 Collection<List<Event>> httpSequences = parser.getSequences(); 74 Model model = 75 ModelUtils.loadModel(ClassLoader76 .getSystemResourceAsStream("createSequence_1_model.uml"));76 77 Model model = 78 ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml")); 77 79 78 80 StateMachine stateMachine = 79 (StateMachine) model.getPackagedElement("PatientIDBehavior", true, 80 UMLPackage.Literals.STATE_MACHINE, true); 81 81 (StateMachine) model.getPackagedElement("StateMachineTransportService", true, 82 UMLPackage.Literals.STATE_MACHINE, true); 83 84 82 85 Collection<List<Event>> umlSequences = new LinkedList<>(); 86 87 // remove everything but transport from sequences 83 88 for (List<Event> httpSequence : httpSequences) { 84 89 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { … … 88 93 } 89 94 else { 90 if (!event.getType().toString().contains("ixsmq")) { 95 SOAPEventType eventType = (SOAPEventType) event.getType(); 96 if (!"TransportService".equals(eventType.getServiceName())) { 91 97 eventIter.remove(); 92 98 } 93 99 } 94 100 } 95 96 101 umlSequences.add(UMLUtils.createUMLTransitionSequence(httpSequence, stateMachine)); 97 102 } … … 100 105 @Test 101 106 public void testConvertStateMachineToUsageProfile_1() throws Exception { 102 // parse log file 103 HTTPLogParser parser = new HTTPLogParser(); 104 parser.parseFile(new File(ClassLoader.getSystemResource("createSequence_1_usagedata.log") 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") 105 111 .getFile())); 106 112 Collection<List<Event>> httpSequences = parser.getSequences(); 107 Model model = 108 ModelUtils.loadModel(ClassLoader 109 .getSystemResourceAsStream("createSequence_1_model.uml")); 110 111 StateMachine stateMachine = 112 (StateMachine) model.getPackagedElement("PatientIDBehavior", true, 113 UMLPackage.Literals.STATE_MACHINE, true); 114 115 Collection<List<Event>> umlSequences = new LinkedList<>(); 113 114 Model model = 115 ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("ita_model_v2.uml")); 116 117 // remove everything but transport from sequences 116 118 for (List<Event> httpSequence : httpSequences) { 117 119 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { … … 121 123 } 122 124 else { 123 if (!event.getType().toString().contains("ixsmq")) { 125 SOAPEventType eventType = (SOAPEventType) event.getType(); 126 if (!"TransportService".equals(eventType.getServiceName())) { 124 127 eventIter.remove(); 125 128 } 126 129 } 127 130 } 128 129 List<List<Transition>> matchingSequences = 130 UMLUtils.determineMatchingTransitionSequences(httpSequence, stateMachine); 131 if (matchingSequences.size() >= 1) { 132 List<Event> umlEventSequence = new LinkedList<>(); 133 for (Transition transition : matchingSequences.get(0)) { 134 umlEventSequence.add(new Event(new UMLTransitionType(transition))); 135 } 136 umlSequences.add(umlEventSequence); 137 } 138 } 139 UMLUtils.convertStateMachineToUsageProfile(umlSequences, stateMachine); 140 141 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "convertStateMachineToUsageProfile_1.uml"); 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"); 142 140 } 143 141 … … 170 168 } 171 169 172 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 173 } 174 170 ModelUtils.writeModelToFile(model, OUTPUT_DIR + 171 "testCreateInteractionFromEventSequence_1_result.uml"); 172 } 173 175 174 @Test 176 175 public void testCreateInteractionFromEventSequence_2() throws Exception { … … 201 200 } 202 201 203 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 204 } 205 202 ModelUtils.writeModelToFile(model, OUTPUT_DIR + 203 "testCreateInteractionFromEventSequence_1_result.uml"); 204 } 205 206 206 @Test 207 207 public void testCalculateUsageScore_1() throws Exception { … … 220 220 Collection<List<Event>> simpleSOAPSequences = new LinkedList<>(); 221 221 for (List<Event> httpSequence : httpSequences) { 222 simpleSOAPSequences.add( HTTPUtils.convertToSimpleSOAPEvent(httpSequence, true));222 simpleSOAPSequences.add(SOAPUtils.convertToSimpleSOAPEvent(httpSequence, true)); 223 223 } 224 224 … … 244 244 } 245 245 } 246 246 247 247 @Test 248 248 public void testCreateScheduling_1() throws Exception { 249 249 Model model = 250 ModelUtils.loadModel(ClassLoader 251 .getSystemResourceAsStream("testCreateScheduling_1_testsuite.uml")); 252 253 IStochasticProcess usageProfile = (IStochasticProcess) SerializationUtils.deserialize(ClassLoader.getSystemResourceAsStream("testCreateScheduling_1_usageprofile.dat")); 254 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 255 257 UMLUtils.createScheduling(model, usageProfile, null); 256 258 257 259 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml"); 258 260 } 259 261 260 262 @Test 261 263 public void testValidateModelWithLog_1() throws Exception { 262 264 HTTPLogParser parser = 263 264 265 265 new HTTPLogParser(new File(ClassLoader 266 .getSystemResource("testCreateInteractionFromEventSequence_1_properties.txt") 267 .getFile())); 266 268 parser 267 269 .parseFile(new File(ClassLoader … … 270 272 Collection<List<Event>> httpSequences = parser.getSequences(); 271 273 274 for (List<Event> httpSequence : httpSequences) { 275 SOAPUtils.removeNonSOAPEvents(httpSequence); 276 } 272 277 273 278 Model model = 274 279 ModelUtils.loadModel(ClassLoader 275 280 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_1_model.uml")); 276 281 277 282 int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 278 if ( violations==0) {283 if (violations == 0) { 279 284 System.out.println("No problems found."); 280 } else { 281 System.out.println(violations + " violations found."); 282 } 283 } 284 285 } 286 else { 287 System.out.println(violations + " violations found."); 288 } 289 } 290 285 291 @Test 286 292 public void testValidateModelWithLog_2() throws Exception { 287 293 HTTPLogParser parser = 288 289 290 294 new HTTPLogParser(new File(ClassLoader 295 .getSystemResource("testCreateInteractionFromEventSequence_2_properties.txt") 296 .getFile())); 291 297 parser 292 298 .parseFile(new File(ClassLoader … … 295 301 Collection<List<Event>> httpSequences = parser.getSequences(); 296 302 303 for (List<Event> httpSequence : httpSequences) { 304 SOAPUtils.removeNonSOAPEvents(httpSequence); 305 } 297 306 298 307 Model model = 299 308 ModelUtils.loadModel(ClassLoader 300 309 .getSystemResourceAsStream("testCreateInteractionFromEventSequence_2_model.uml")); 301 310 302 311 int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 303 if ( violations==0) {312 if (violations == 0) { 304 313 System.out.println("No problems found."); 305 } else { 314 } 315 else { 306 316 System.out.println(violations + " violations found."); 307 317 } 308 318 } 309 319 310 320 @Test 311 321 public void testValidateModelWithLog_HL7_RLUS_v3() throws Exception { 312 322 HTTPLogParser parser = 313 new HTTPLogParser(new File(ClassLoader 314 .getSystemResource("hl7_servicenamemap.txt") 315 .getFile())); 323 new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_servicenamemap.txt") 324 .getFile())); 316 325 parser 317 326 .parseFile(new File(ClassLoader … … 320 329 Collection<List<Event>> httpSequences = parser.getSequences(); 321 330 322 323 Model model = 324 ModelUtils.loadModel(ClassLoader 325 .getSystemResourceAsStream("hl7model_v3.uml")); 326 331 for (List<Event> httpSequence : httpSequences) { 332 SOAPUtils.removeNonSOAPEvents(httpSequence); 333 } 334 335 Model model = 336 ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml")); 337 327 338 int violations = UMLUtils.validateModelWithLog(httpSequences, model, "RLUSTestSuite_1"); 328 if ( violations==0) {339 if (violations == 0) { 329 340 System.out.println("No problems found."); 330 } else { 341 } 342 else { 331 343 System.out.println(violations + " violations found."); 332 344 } 333 345 334 346 // remove everything but rlusService from sequences 335 347 for (List<Event> httpSequence : httpSequences) { 336 348 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 337 349 Event event = eventIter.next(); 338 if (!(event.getType() instanceof SOAPEventType)) { 339 eventIter.remove(); 340 } else { 341 SOAPEventType eventType = (SOAPEventType) event.getType(); 342 if( !"rlusService".equals(eventType.getServiceName()) ) { 343 eventIter.remove(); 344 } 345 } 346 } 347 348 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", "RLUSTestSuite_1"); 349 } 350 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 351 362 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml"); 352 363 } 353 364 354 365 @Test 355 366 public void testValidateModelWithLog_HL7_IXS_v3() throws Exception { 356 367 HTTPLogParser parser = 357 new HTTPLogParser(new File(ClassLoader 358 .getSystemResource("hl7_ixs_servicenamemap.txt") 359 .getFile())); 368 new HTTPLogParser(new File(ClassLoader.getSystemResource("hl7_ixs_servicenamemap.txt") 369 .getFile())); 360 370 parser 361 371 .parseFile(new File(ClassLoader … … 364 374 Collection<List<Event>> httpSequences = parser.getSequences(); 365 375 366 367 Model model = 368 ModelUtils.loadModel(ClassLoader 369 .getSystemResourceAsStream("hl7model_v3.uml")); 370 376 for (List<Event> httpSequence : httpSequences) { 377 SOAPUtils.removeNonSOAPEvents(httpSequence); 378 } 379 380 Model model = 381 ModelUtils.loadModel(ClassLoader.getSystemResourceAsStream("hl7model_v3.uml")); 382 371 383 int violations = UMLUtils.validateModelWithLog(httpSequences, model, "IXSTestSuite_1"); 372 if ( violations==0) {384 if (violations == 0) { 373 385 System.out.println("No problems found."); 374 } else { 386 } 387 else { 375 388 System.out.println(violations + " violations found."); 376 389 } 377 390 378 391 // remove everything but rlusService from sequences 379 392 for (List<Event> httpSequence : httpSequences) { 380 393 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 381 394 Event event = eventIter.next(); 382 if (!(event.getType() instanceof SOAPEventType)) { 383 eventIter.remove(); 384 } else { 385 SOAPEventType eventType = (SOAPEventType) event.getType(); 386 if( !"ixsService".equals(eventType.getServiceName()) ) { 387 eventIter.remove(); 388 } 389 } 390 } 391 392 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", "IXSTestSuite_1"); 393 } 394 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 395 405 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "hl7_v3_result.uml"); 396 406 } 397 407 398 408 @Test 399 409 public void testValidateModelWithLog_ITA_v2() throws Exception { 400 410 HTTPLogParser parser = 401 new HTTPLogParser(new File(ClassLoader 402 .getSystemResource("ita_v2_servicenamemap.txt") 403 .getFile())); 404 parser 405 .parseFile(new File(ClassLoader 406 .getSystemResource("ita_usagejournal_v2_2.log") 407 .getFile())); 408 Collection<List<Event>> httpSequences = parser.getSequences(); 409 410 411 Model model = 412 ModelUtils.loadModel(ClassLoader 413 .getSystemResourceAsStream("ita_model_v2.uml")); 414 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 415 424 int violations = UMLUtils.validateModelWithLog(httpSequences, model, null); 416 if ( violations==0) {425 if (violations == 0) { 417 426 System.out.println("No problems found."); 418 } else { 427 } 428 else { 419 429 System.out.println(violations + " violations found."); 420 430 } 421 431 422 432 // remove everything but transport from sequences 423 433 for (List<Event> httpSequence : httpSequences) { 424 434 for (Iterator<Event> eventIter = httpSequence.iterator(); eventIter.hasNext();) { 425 435 Event event = eventIter.next(); 426 if (!(event.getType() instanceof SOAPEventType)) { 427 eventIter.remove(); 428 } else { 429 SOAPEventType eventType = (SOAPEventType) event.getType(); 430 if( !"TransportService".equals(eventType.getServiceName()) ) { 431 eventIter.remove(); 432 } 433 } 434 } 435 436 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", "LogisticsTestSuite"); 437 } 438 436 SOAPEventType eventType = (SOAPEventType) event.getType(); 437 if (!"TransportService".equals(eventType.getServiceName())) { 438 eventIter.remove(); 439 } 440 } 441 442 UMLUtils.createInteractionFromEventSequence(httpSequence, model, "foo", 443 "LogisticsTestSuite"); 444 } 445 439 446 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "ita_v2_result.uml"); 440 447 441 448 } 442 449
Note: See TracChangeset
for help on using the changeset viewer.