Changeset 1898
- Timestamp:
- 03/06/15 09:18:02 (10 years ago)
- 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 21 21 import java.util.List; 22 22 import java.util.Random; 23 import java.util.logging.Level; 23 24 24 25 import org.apache.commons.lang.SerializationUtils; … … 29 30 import org.eclipse.uml2.uml.UMLPackage; 30 31 import org.junit.After; 32 import org.junit.BeforeClass; 31 33 import org.junit.Test; 32 34 … … 40 42 import de.ugoe.cs.autoquest.usageprofiles.FirstOrderMarkovModel; 41 43 import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; 44 import de.ugoe.cs.util.console.Console; 45 import de.ugoe.cs.util.console.TextConsole; 42 46 43 47 /** … … 52 56 private final static String OUTPUT_DIR = "target/tmp/test-outputs/"; 53 57 54 /** 55 * 56 */ 58 @BeforeClass 59 public static void setUpBeforeClass() throws Exception { 60 Console.getInstance().registerTraceListener(new TextConsole(Level.INFO)); 61 } 62 57 63 @After 58 64 public void tearDown() throws Exception { … … 181 187 Collection<List<Event>> httpSequences = parser.getSequences(); 182 188 183 184 189 Model model = 185 190 ModelUtils.loadModel(ClassLoader … … 197 202 } 198 203 199 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_2_result.uml"); 200 204 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateInteractionFromEventSequence_1_result.uml"); 201 205 } 202 206 … … 294 298 ModelUtils.writeModelToFile(model, OUTPUT_DIR + "testCreateScheduling_1_result.uml"); 295 299 } 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 } 296 360 297 361 private void deleteFiles(File file) { -
trunk/autoquest-plugin-uml-test/src/test/resources/hl7_servicenamemap.txt
r1896 r1898 2 2 /midas/rlus/update/xdw = rlusService 3 3 /midas/rlus/update/cda2report = rlusService 4 /midas/ixsmq/update/pocdpatient = ixs mq_property5 /midas/ixsmq/query/pocdpatient = ixs mq_property4 /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 19 19 import java.util.Comparator; 20 20 import java.util.HashMap; 21 import java.util.HashSet; 21 22 import java.util.Iterator; 22 23 import java.util.LinkedHashMap; … … 25 26 import java.util.Map; 26 27 import java.util.Map.Entry; 28 import java.util.logging.Level; 29 import java.util.Set; 30 import java.util.TreeSet; 27 31 28 32 import org.eclipse.emf.common.util.EList; … … 30 34 import org.eclipse.uml2.uml.ActivityEdge; 31 35 import org.eclipse.uml2.uml.ActivityNode; 32 import org.eclipse.uml2.uml. BehaviorExecutionSpecification;36 import org.eclipse.uml2.uml.CallConcurrencyKind; 33 37 import org.eclipse.uml2.uml.CallOperationAction; 34 38 import org.eclipse.uml2.uml.Comment; … … 62 66 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 63 67 import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; 68 import de.ugoe.cs.util.console.Console; 64 69 65 70 /** … … 72 77 public class UMLUtils { 73 78 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 74 187 /** 75 188 * <p> … … 355 468 } 356 469 // determine correct target interface 357 List<Interface> targetInterfaces =470 Set<Interface> targetInterfaces = 358 471 getRealizedInterfacesFromProperty((Property) msgTargetLifeline.getRepresents()); 359 472 if (targetInterfaces.isEmpty()) { … … 363 476 Interface targetInterface = null; 364 477 for (Interface intface : targetInterfaces) { 365 System.out.println(intface.getOperations());366 478 if (getOperationFromName(intface.getOperations(), methodName) != null) { 367 479 // interface found … … 412 524 callRecvFragment.setMessage(callMessage); 413 525 414 // TODO somehow infer if called operation is SYNCH or ASYNCH415 // possibly requires additional stereotype416 526 boolean asynch = false; 527 if( calledOperation.getConcurrency()==CallConcurrencyKind.CONCURRENT_LITERAL ) { 528 asynch = true; 529 } 417 530 if (asynch) { 418 531 // Create ASYNCH call … … 700 813 } 701 814 702 private static List<Interface> getRealizedInterfacesFromProperty(Property property) {815 private static Set<Interface> getRealizedInterfacesFromProperty(Property property) { 703 816 return getRealizedInterfaceFromComponent((Component) property.getType()); 704 817 } 705 818 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<>(); 708 821 // Interface myInterface = null; 709 822 for (Property property : comp.getAttributes()) {
Note: See TracChangeset
for help on using the changeset viewer.