- Timestamp:
- 07/09/15 13:51:51 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java
r1993 r1995 52 52 import org.eclipse.uml2.uml.LiteralBoolean; 53 53 import org.eclipse.uml2.uml.LiteralInteger; 54 import org.eclipse.uml2.uml.LiteralNull; 54 55 import org.eclipse.uml2.uml.LiteralReal; 55 56 import org.eclipse.uml2.uml.LiteralString; … … 79 80 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 80 81 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 82 import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType; 81 83 import de.ugoe.cs.autoquest.plugin.uml.eventcore.UMLTransitionType; 82 84 import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess; … … 457 459 for (Property property : fetchAllTestComponentProperties(testContext)) { 458 460 // TODO check if this is still required 459 /*if (userLifeline != null) { 460 throw new RuntimeException( 461 "TestContext must only have one TestComponent for the application of usage-based testing."); 462 }*/ 461 /* 462 * if (userLifeline != null) { throw new RuntimeException( 463 * "TestContext must only have one TestComponent for the application of usage-based testing." 464 * ); } 465 */ 463 466 userLifeline = interaction.createLifeline(property.getName()); 464 467 userLifeline.setRepresents(property); … … 531 534 Operation calledOperation = 532 535 getOperationFromName(targetInterface.getOperations(), methodName); 533 534 // setup for both SYNCH and ASYNCH calls535 MessageOccurrenceSpecification callSendFragment =536 (MessageOccurrenceSpecification) interaction.createFragment(prefix +537 "callSendFragment", UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);538 MessageOccurrenceSpecification callRecvFragment =539 (MessageOccurrenceSpecification) interaction.createFragment(prefix +540 "callRecvFragment", UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);541 542 callSendFragment.setCovered(msgSourceLifeline);543 callRecvFragment.setCovered(msgTargetLifeline);544 545 536 // get connector 546 537 Connector connector = inferConnector(msgSourceLifeline, msgTargetLifeline); 547 548 // create call549 Message callMessage = interaction.createMessage(prefix + "call");550 callMessage.setSignature(calledOperation);551 setCallMessageParameters(callMessage, calledOperation, event, useRandomRequestBodies, prefix);552 callMessage.setConnector(connector);553 callMessage.setSendEvent(callSendFragment);554 callMessage.setReceiveEvent(callRecvFragment);555 callSendFragment.setMessage(callMessage);556 callRecvFragment.setMessage(callMessage);557 538 558 539 boolean asynch = false; … … 560 541 asynch = true; 561 542 } 562 if (asynch) { 563 // Create ASYNCH call 564 callMessage.setMessageSort(MessageSort.ASYNCH_CALL_LITERAL); 565 } 566 else { 567 // SYNCH call 568 callMessage.setMessageSort(MessageSort.SYNCH_CALL_LITERAL); 569 543 544 if (SOAPUtils.isSOAPRequest(event)) { 545 // setup for both SYNCH and ASYNCH calls 546 MessageOccurrenceSpecification callSendFragment = 547 (MessageOccurrenceSpecification) interaction 548 .createFragment(prefix + "callSendFragment", 549 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 550 MessageOccurrenceSpecification callRecvFragment = 551 (MessageOccurrenceSpecification) interaction 552 .createFragment(prefix + "callRecvFragment", 553 UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION); 554 555 callSendFragment.setCovered(msgSourceLifeline); 556 callRecvFragment.setCovered(msgTargetLifeline); 557 558 // create call 559 Message callMessage = interaction.createMessage(prefix + "call"); 560 callMessage.setSignature(calledOperation); 561 setCallMessageParameters(callMessage, calledOperation, event, 562 useRandomRequestBodies, prefix); 563 callMessage.setConnector(connector); 564 callMessage.setSendEvent(callSendFragment); 565 callMessage.setReceiveEvent(callRecvFragment); 566 callSendFragment.setMessage(callMessage); 567 callRecvFragment.setMessage(callMessage); 568 569 if (asynch) { 570 // Create ASYNCH call 571 callMessage.setMessageSort(MessageSort.ASYNCH_CALL_LITERAL); 572 } 573 else { 574 // SYNCH call 575 callMessage.setMessageSort(MessageSort.SYNCH_CALL_LITERAL); 576 } 577 } 578 if (!asynch && SOAPUtils.isSOAPResponse(event)) { 570 579 // setup reply and behavior execution specifications 571 580 MessageOccurrenceSpecification replySendFragment = … … 647 656 .get(0).getName(); 648 657 String methodName = message.getSignature().getName(); 658 // TODO must be updated 649 659 eventSequence.add(new Event(new SimpleSOAPEventType(methodName, serviceName, 650 clientName, null )));660 clientName, null, null, null))); 651 661 } 652 662 } … … 783 793 String transitionService = 784 794 interfaceServiceMap.get(callEvent.getOperation().getInterface()); 785 795 786 796 if (eventMethod.equals(transitionMethod) && 787 797 eventService.equals(transitionService)) … … 790 800 } 791 801 } 792 } else { 793 throw new RuntimeException("only one trigger of type CallEvent per transition allowed: " + transition.getName()); 802 } 803 else { 804 throw new RuntimeException( 805 "only one trigger of type CallEvent per transition allowed: " + 806 transition.getName()); 794 807 } 795 808 … … 1039 1052 String prefix) 1040 1053 { 1041 org.w3c.dom.Element requestBody = SOAPUtils.getSoapBodyFromEvent(event, useRandomRequestBodies); 1054 org.w3c.dom.Element requestBody = 1055 SOAPUtils.getSoapBodyFromEvent(event, useRandomRequestBodies, CallType.REQUEST); 1042 1056 Package instSpecPkg = null; 1043 1057 1044 1058 // FOR DEBUGGING 1045 //Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE +1046 //SOAPUtils.getSerialization(requestBody));1047 //for( Parameter param : calledOperation.getOwnedParameters() ) {1048 //System.out.println(param.getName());1049 //if( param.getType() instanceof DataType ) {1050 //for( Property prop1 : ((DataType) param.getType()).getAllAttributes() ) {1051 //System.out.println(" " + prop1.getName());1052 //if( prop1.getType() instanceof DataType ) {1053 //for( Property prop2 : ((DataType) prop1.getType()).getAllAttributes() ) {1054 //System.out.println(" " + prop2.getName());1055 //if( prop2.getType() instanceof DataType ) {1056 //for( Property prop3 : ((DataType) prop2.getType()).getAllAttributes() ) {1057 //System.out.println(" " + prop3.getName());1058 //if( prop3.getType() instanceof DataType ) {1059 //for( Property prop4 : ((DataType) prop3.getType()).getAllAttributes() ) {1060 //System.out.println(" " + prop4.getName());1061 //}1062 //}1063 //}1064 //}1065 //}1066 //}1067 //}1068 //}1069 //}1070 1059 // Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE + 1060 // SOAPUtils.getSerialization(requestBody)); 1061 // for( Parameter param : calledOperation.getOwnedParameters() ) { 1062 // System.out.println(param.getName()); 1063 // if( param.getType() instanceof DataType ) { 1064 // for( Property prop1 : ((DataType) param.getType()).getAllAttributes() ) { 1065 // System.out.println(" " + prop1.getName()); 1066 // if( prop1.getType() instanceof DataType ) { 1067 // for( Property prop2 : ((DataType) prop1.getType()).getAllAttributes() ) { 1068 // System.out.println(" " + prop2.getName()); 1069 // if( prop2.getType() instanceof DataType ) { 1070 // for( Property prop3 : ((DataType) prop2.getType()).getAllAttributes() ) { 1071 // System.out.println(" " + prop3.getName()); 1072 // if( prop3.getType() instanceof DataType ) { 1073 // for( Property prop4 : ((DataType) prop3.getType()).getAllAttributes() ) { 1074 // System.out.println(" " + prop4.getName()); 1075 // } 1076 // } 1077 // } 1078 // } 1079 // } 1080 // } 1081 // } 1082 // } 1083 // } 1084 1071 1085 // Set parameters of operation 1072 1086 for (Parameter param : calledOperation.getOwnedParameters()) { 1073 1087 if (instSpecPkg == null) { 1074 instSpecPkg = getOrCreateInstanceSpecificationPackage(callMessage.getModel(), event); 1088 instSpecPkg = 1089 getOrCreateInstanceSpecificationPackage(callMessage.getModel(), event); 1075 1090 } 1076 1091 … … 1078 1093 String path = calledOperation.getName() + ":" + param.getType().getName(); 1079 1094 // create param node 1080 //Expression argument =1081 //(Expression) callMessage.createArgument(param.getName(), param.getType(),1082 //UMLPackage.Literals.EXPRESSION);1095 // Expression argument = 1096 // (Expression) callMessage.createArgument(param.getName(), param.getType(), 1097 // UMLPackage.Literals.EXPRESSION); 1083 1098 if (isInParameter(param)) { 1084 1099 1085 1100 // create parameters node 1086 if (!(param.getType() instanceof DataType) 1101 if (!(param.getType() instanceof DataType)) { 1087 1102 throw new RuntimeException("TODO error handling; parameters missing"); 1088 1103 } 1089 1104 DataType parametersNode = (DataType) param.getType(); 1090 InstanceSpecification instSpecParameters = (InstanceSpecification)1091 instSpecPkg.createPackagedElement(prefix + "instspec_" + param.getType().getName(),1092 1105 InstanceSpecification instSpecParameters = 1106 (InstanceSpecification) instSpecPkg.createPackagedElement(prefix + "instspec_" + 1107 param.getType().getName(), UMLPackage.Literals.INSTANCE_SPECIFICATION); 1093 1108 instSpecParameters.getClassifiers().add((DataType) param.getType()); 1094 // InstanceValue parametersValue = 1095 // (InstanceValue) argument 1096 // .createOperand(param.getType().getName(), param.getType(), 1097 // UMLPackage.Literals.INSTANCE_VALUE); 1098 // parametersValue.setInstance(instSpecParameters); 1099 InstanceValue instanceValue = (InstanceValue) callMessage.createArgument(param.getName(), param.getType(), UMLPackage.Literals.INSTANCE_VALUE); 1109 // InstanceValue parametersValue = 1110 // (InstanceValue) argument 1111 // .createOperand(param.getType().getName(), param.getType(), 1112 // UMLPackage.Literals.INSTANCE_VALUE); 1113 // parametersValue.setInstance(instSpecParameters); 1114 InstanceValue instanceValue = 1115 (InstanceValue) callMessage.createArgument(param.getName(), param.getType(), 1116 UMLPackage.Literals.INSTANCE_VALUE); 1100 1117 instanceValue.setInstance(instSpecParameters); 1101 1102 for ( Property internalParameter : parametersNode.getAllAttributes()) {1118 1119 for (Property internalParameter : parametersNode.getAllAttributes()) { 1103 1120 if (internalParameter.getType() instanceof DataType) { 1104 1121 List<org.w3c.dom.Element> paramNodes = 1105 SOAPUtils.getMatchingChildNode(internalParameter.getType().getName(), requestBody); 1122 SOAPUtils.getMatchingChildNode(internalParameter.getType().getName(), 1123 requestBody); 1106 1124 // TODO the mistake is somewhere around here ... probably 1107 // List<org.w3c.dom.Element> paramNodes =1108 // 1125 // List<org.w3c.dom.Element> paramNodes = 1126 // SOAPUtils.getMatchingChildNode(param.getName(), requestBody); 1109 1127 int multiplicityChosen = paramNodes.size(); 1110 1128 1111 1129 if (multiplicityChosen == 0 && internalParameter.getLower() > 0) { 1112 Console.traceln(Level.WARNING, 1113 "required attribute not found in SOAP message: " + path); 1130 Console 1131 .traceln(Level.WARNING, 1132 "required attribute not found in SOAP message: " + path); 1114 1133 Console 1115 1134 .traceln(Level.WARNING, 1116 1135 "setting default values for this attribute and all its children"); 1117 Console.traceln(Level.FINE, "XML structure of path:" + StringTools.ENDLINE +1118 S OAPUtils.getSerialization(requestBody));1136 Console.traceln(Level.FINE, "XML structure of path:" + 1137 StringTools.ENDLINE + SOAPUtils.getSerialization(requestBody)); 1119 1138 multiplicityChosen = internalParameter.getLower(); 1120 1139 } … … 1124 1143 paramNode = paramNodes.get(i); 1125 1144 } 1126 1145 1127 1146 Slot slot = instSpecParameters.createSlot(); 1128 1147 slot.setDefiningFeature(internalParameter); 1129 1148 1130 1149 InstanceValue value = 1131 (InstanceValue) slot.createValue(internalParameter.getName() + "_" + i, internalParameter.getType(), 1132 UMLPackage.Literals.INSTANCE_VALUE); 1133 value.setInstance(createInstanceSpecification((DataType) internalParameter.getType(), instSpecPkg, 1134 prefix, paramNode, path)); 1150 (InstanceValue) slot 1151 .createValue(internalParameter.getName() + "_" + i, 1152 internalParameter.getType(), 1153 UMLPackage.Literals.INSTANCE_VALUE); 1154 value 1155 .setInstance(createInstanceSpecification((DataType) internalParameter 1156 .getType(), 1157 instSpecPkg, prefix, 1158 paramNode, path)); 1135 1159 /* 1136 InstanceValue value = 1137 (InstanceValue) argument 1138 .createOperand(null, internalParameter.getType(), 1139 UMLPackage.Literals.INSTANCE_VALUE); 1140 value.setInstance(instSpec);*/ 1160 * InstanceValue value = (InstanceValue) argument .createOperand(null, 1161 * internalParameter.getType(), UMLPackage.Literals.INSTANCE_VALUE); 1162 * value.setInstance(instSpec); 1163 */ 1141 1164 } 1142 1165 } 1143 1166 else if (internalParameter.getType() instanceof PrimitiveType) { 1144 createSlotPrimitiveType(instSpecParameters, internalParameter, requestBody, path); 1167 createSlotPrimitiveType(instSpecParameters, internalParameter, requestBody, 1168 path); 1145 1169 } 1146 1170 } … … 1148 1172 else { 1149 1173 // set literalNull for out and return parameters 1150 // argument.createOperand(null, param.getType(), UMLPackage.Literals.LITERAL_NULL); 1151 callMessage.createArgument(param.getName(), param.getType(), UMLPackage.Literals.LITERAL_NULL); 1174 // argument.createOperand(null, param.getType(), UMLPackage.Literals.LITERAL_NULL); 1175 callMessage.createArgument(param.getName(), param.getType(), 1176 UMLPackage.Literals.LITERAL_NULL); 1152 1177 } 1153 1178 } … … 1197 1222 int multiplicityChosen = 0; 1198 1223 if (currentNode != null) { 1199 // TODO attributeNodes = SOAPUtils.getMatchingChildNode(prop.getName(), currentNode); 1224 // TODO attributeNodes = SOAPUtils.getMatchingChildNode(prop.getName(), 1225 // currentNode); 1200 1226 attributeNodes = SOAPUtils.getMatchingChildNode(prop.getName(), currentNode); 1201 1227 multiplicityChosen = attributeNodes.size(); … … 1467 1493 private static void setReplyMessageParameters(Message replyMessage, Operation calledOperation) { 1468 1494 for (Parameter param : calledOperation.getOwnedParameters()) { 1469 Expression argument = 1470 (Expression) replyMessage.createArgument(param.getName(), param.getType(), 1471 UMLPackage.Literals.EXPRESSION); 1472 ValueSpecification operand = 1473 argument.createOperand(null, param.getType(), UMLPackage.Literals.LITERAL_NULL); 1495 LiteralNull argument = 1496 (LiteralNull) replyMessage.createArgument(param.getName(), param.getType(), 1497 UMLPackage.Literals.LITERAL_NULL); 1498 1474 1499 if (isOutParameter(param)) { 1475 operand.applyStereotype(UTPUtils.getLiteralAnyStereotype(replyMessage.getModel()));1500 argument.applyStereotype(UTPUtils.getLiteralAnyStereotype(replyMessage.getModel())); 1476 1501 } 1477 1502 }
Note: See TracChangeset
for help on using the changeset viewer.