Changeset 1898 for trunk/autoquest-plugin-uml
- Timestamp:
- 03/06/15 09:18:02 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.