Changeset 1900 for trunk/autoquest-plugin-uml/src/main
- Timestamp:
- 03/06/15 10:24:54 (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
r1898 r1900 77 77 public class UMLUtils { 78 78 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 { 80 97 final Profile utpProfile = model.getAppliedProfile("utp"); 81 98 final Stereotype utpTestComponent = (Stereotype) utpProfile.getOwnedMember("TestComponent"); … … 83 100 final Stereotype utpTestContext = (Stereotype) utpProfile.getOwnedMember("TestContext"); 84 101 102 int violationCount = 0; 85 103 Component testContext = fetchTestContext(model, utpTestContext, testContextName); 86 104 if (testContext == null) { 87 if( testContextName==null ) { 105 violationCount++; 106 if (testContextName == null) { 88 107 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 96 121 // Create list of unique methods calls 97 122 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) { 101 126 SOAPEventType eventType = (SOAPEventType) event.getType(); 102 127 Set<String> curCalledMethods = calledMethods.get(eventType.getServiceName()); 103 if ( curCalledMethods==null) {128 if (curCalledMethods == null) { 104 129 curCalledMethods = new TreeSet<>(); 105 130 calledMethods.put(eventType.getServiceName(), curCalledMethods); … … 109 134 } 110 135 } 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() + "\": "); 115 141 Iterator<String> iter = entry.getValue().iterator(); 116 142 StringBuilder strBld = new StringBuilder(); … … 123 149 Console.traceln(Level.INFO, strBld.toString()); 124 150 } 125 151 126 152 // fetch all SUTs and TestComponents 127 153 HashMap<String, Property> properties = new HashMap<>(); 128 154 for (Property property : testContext.getAllAttributes()) { 129 155 if (property.getAppliedStereotypes().contains(utpSUT)) { 130 properties.put(property.getName(), property);156 properties.put(property.getName(), property); 131 157 } 132 158 else if (property.getType().getAppliedStereotypes().contains(utpTestComponent)) { 133 properties.put(property.getName(), property);159 properties.put(property.getName(), property); 134 160 } 135 161 } 136 162 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()) { 138 164 Console.traceln(Level.INFO, "\t" + entry.getKey()); 139 165 } 140 141 for ( Entry<String, Set<String>> entry : calledMethods.entrySet()) {166 167 for (Entry<String, Set<String>> entry : calledMethods.entrySet()) { 142 168 String serviceName = entry.getKey(); 143 169 Console.traceln(Level.INFO, "Checking service: " + serviceName); 144 170 Set<String> methodNames = entry.getValue(); 145 171 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 { 151 184 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(); 158 200 while (iter.hasNext()) { 159 201 String interfaceName = iter.next().getName(); … … 165 207 Console.traceln(Level.INFO, strBld.toString()); 166 208 } 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) { 170 212 if (getOperationFromName(intface.getOperations(), methodName) != null) { 171 213 // 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()); 173 216 methodFound = true; 174 217 } 175 218 } 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"); 179 226 } 180 227 } … … 182 229 } 183 230 } 184 185 } 186 231 return violationCount; 232 } 233 187 234 /** 188 235 * <p> … … 412 459 // create lifelines 413 460 Lifeline userLifeline = null; 414 461 415 462 for (Property property : testContext.getAllAttributes()) { 416 463 if (property.getAppliedStereotypes().contains(utpSUT)) { … … 420 467 } 421 468 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."); 424 472 } 425 473 userLifeline = interaction.createLifeline(property.getName()); … … 427 475 } 428 476 } 429 if ( userLifeline==null) {477 if (userLifeline == null) { 430 478 throw new RuntimeException("No TestComponent found, could not create user lifeline."); 431 479 } 432 if ( interaction.getLifelines().size()<2) {480 if (interaction.getLifelines().size() < 2) { 433 481 throw new RuntimeException("Fewer than two lifelines created. No SUT found."); 434 482 } 435 483 436 484 int i = 0; 437 485 for (Event event : sequence) { … … 461 509 msgTargetLifeline = interaction.getLifeline(serviceName); 462 510 } 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."); 468 518 } 469 519 // determine correct target interface … … 484 534 if (targetInterface == null) { 485 535 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 ("); 487 538 Iterator<Interface> iter = targetInterfaces.iterator(); 488 539 while (iter.hasNext()) { … … 525 576 526 577 boolean asynch = false; 527 if ( calledOperation.getConcurrency()==CallConcurrencyKind.CONCURRENT_LITERAL) {578 if (calledOperation.getConcurrency() == CallConcurrencyKind.CONCURRENT_LITERAL) { 528 579 asynch = true; 529 580 } … … 548 599 replySendFragment.setCovered(msgTargetLifeline); 549 600 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 */ 564 617 565 618 // create reply … … 824 877 Port port = (Port) property; 825 878 if (!port.isConjugated()) { 826 interfaces.addAll(port.getProvideds()); 879 interfaces.addAll(port.getProvideds()); 827 880 } 828 881 } … … 871 924 /** 872 925 * <p> 873 * Infers connector between two lifelines. 874 * TODO: currently assumes only one connector betweentwo 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. 875 928 * </p> 876 929 *
Note: See TracChangeset
for help on using the changeset viewer.