Changeset 1993


Ignore:
Timestamp:
07/08/15 13:09:44 (9 years ago)
Author:
sherbold
Message:
  • SimpleSOAPEventType can now either be a request or a response and contains the appropriate soap message body
  • SOAPUtils offer function to convert SOAPEventType into SimpleSOAPEventType and meanwhile split into request and response and sort the SimpleSOAPEvents in the appropriate order
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java

    r1992 r1993  
    4040import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
    4141import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 
     42import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType; 
    4243 
    4344/** 
     
    220221     * @return body of the SOAP event 
    221222     */ 
    222     public static Element getSoapRequestBodyFromEvent(Event event) { 
    223         return getSoapRequestBodyFromEvent(event, false); 
     223    public static Element getSoapBodyFromEvent(Event event) { 
     224        return getSoapBodyFromEvent(event, false); 
    224225    } 
    225226 
     
    235236     * @return body of the SOAP event 
    236237     */ 
    237     public static Element getSoapRequestBodyFromEvent(Event event, boolean useRandomRequestBodies) { 
     238    public static Element getSoapBodyFromEvent(Event event, boolean useRandomRequestBodies) { 
    238239        Element requestBody = null; 
    239240        if (event.getType() instanceof SOAPEventType) { 
     
    242243        else if (event.getType() instanceof SimpleSOAPEventType) { 
    243244            if (useRandomRequestBodies) { 
    244                 requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapRequestBody(); 
     245                requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapMsgBody(); 
    245246            } 
    246247            else { 
    247                 requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 
     248                requestBody = ((SimpleSOAPEventType) event.getType()).getSoapMsgBody(); 
    248249            } 
    249250        } 
     
    382383                        new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), 
    383384                                                          eventType.getClientName(), 
    384                                                           eventType.getSoapRequestBody(), 
     385                                                          eventType.getSoapMsgBody(), 
    385386                                                          eventType.getEqualSOAPDataMap()), 
    386387                                  event.getTarget()); 
     
    457458        return sortedSequences; 
    458459    } 
    459      
     460 
     461    /** 
     462     * <p> 
     463     * Sorts the sequences by the orderingId of the requests/responses. This function only supports 
     464     * the ordering of {@link Event}s with a {@link SOAPEventType}. 
     465     * </p> 
     466     *  
     467     * @param sequences 
     468     *            sequences to be order 
     469     * @param orderType 
     470     *            determines if sequences are ordered by request or response 
     471     * @return sorted sequences 
     472     */ 
     473    public static Collection<List<Event>> sortAndConvertSequences(Collection<List<Event>> sequences, 
     474                                                                  boolean keepRequests, 
     475                                                                  boolean keepResponse) 
     476    { 
     477        Collection<List<Event>> sortedSequences = new LinkedList<>(); 
     478        EqualSOAPDataMap equalSOAPDataMap = new EqualSOAPDataMap(); 
     479        for (List<Event> sequence : sequences) { 
     480            // use insertion sort 
     481            List<Event> sortedSequence = new LinkedList<>(); 
     482            long lastOrderId = Long.MIN_VALUE; 
     483            long selectedOrderId; 
     484            Event selectedEvent; 
     485            CallType selectedCallType = CallType.RESPONSE; 
     486            do { 
     487                selectedEvent = null; 
     488                selectedOrderId = Long.MAX_VALUE; 
     489                for (Event event : sequence) { 
     490                    if (!(event.getType() instanceof SOAPEventType)) { 
     491                        throw new RuntimeException( 
     492                                                   "Can only order SOAPEventTypes. SimpleSOAPEvent is also not supported. Event type found: " + 
     493                                                       event.getType().getClass().getName()); 
     494                    } 
     495                    SOAPEventType soapEventType = (SOAPEventType) event.getType(); 
     496                    long requestOrderId = soapEventType.getExchange().getRequest().getOrderingId(); 
     497                    long responseOrderId = 
     498                        soapEventType.getExchange().getResponse().getOrderingId(); 
     499 
     500                    if (requestOrderId > lastOrderId && requestOrderId < selectedOrderId) { 
     501                        selectedOrderId = requestOrderId; 
     502                        selectedEvent = event; 
     503                        selectedCallType = CallType.REQUEST; 
     504                    } 
     505                    if (responseOrderId > lastOrderId && responseOrderId < selectedOrderId) { 
     506                        selectedOrderId = responseOrderId; 
     507                        selectedEvent = event; 
     508                        selectedCallType = CallType.RESPONSE; 
     509                    } 
     510                } 
     511                if (selectedEvent != null) { 
     512                    SOAPEventType eventType = (SOAPEventType) selectedEvent.getType(); 
     513                    Element soapMsgBody; 
     514                    switch (selectedCallType) 
     515                    { 
     516                        case REQUEST: 
     517                            soapMsgBody = eventType.getSoapRequestBody(); 
     518                            break; 
     519                        case RESPONSE: 
     520                            soapMsgBody = eventType.getSoapResponseBody(); 
     521                            break; 
     522                        default: 
     523                            throw new RuntimeException("unsupported call type: " + selectedCallType); 
     524                    } 
     525                    if ((keepRequests && selectedCallType == CallType.REQUEST) || 
     526                        (keepResponse && selectedCallType == CallType.RESPONSE)) 
     527                    { 
     528                        sortedSequence.add(new Event(new SimpleSOAPEventType(eventType 
     529                            .getCalledMethod(), eventType.getServiceName(), eventType 
     530                            .getClientName(), soapMsgBody, equalSOAPDataMap, selectedCallType))); 
     531                    } 
     532                    lastOrderId = selectedOrderId; 
     533                } 
     534                 
     535            } while(selectedEvent!=null); 
     536            sortedSequences.add(sortedSequence); 
     537        } 
     538        return sortedSequences; 
     539    } 
     540 
    460541    /** 
    461542     * <p> 
    462543     * Removes calls to and from all ignored services from the sequences. 
    463544     * </p> 
    464      * 
    465      * @param sequences sequences where the ignored services are removed 
    466      * @param ignoredServicesString comma separted string that defines the ignored services 
     545     *  
     546     * @param sequences 
     547     *            sequences where the ignored services are removed 
     548     * @param ignoredServicesString 
     549     *            comma separted string that defines the ignored services 
    467550     * @return sequences without events that reference the ignored services 
    468551     */ 
    469     public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, String ignoredServicesString) { 
     552    public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, 
     553                                                                       String ignoredServicesString) 
     554    { 
    470555        Set<String> ignoredServices = new HashSet<>(); 
    471556        if (ignoredServicesString != null) { 
     
    476561        return removeCallsToIgnoredServices(sequences, ignoredServices); 
    477562    } 
    478      
     563 
    479564    /** 
    480565     * <p> 
    481566     * Removes calls to and from all ignored services from the sequences. 
    482567     * </p> 
    483      * 
    484      * @param sequences sequences where the ignored services are removed 
    485      * @param ignoredServices set with all ignored service names 
     568     *  
     569     * @param sequences 
     570     *            sequences where the ignored services are removed 
     571     * @param ignoredServices 
     572     *            set with all ignored service names 
    486573     * @return sequences without events that reference the ignored services 
    487574     */ 
    488     public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, Set<String> ignoredServices) { 
     575    public static Collection<List<Event>> removeCallsToIgnoredServices(Collection<List<Event>> sequences, 
     576                                                                       Set<String> ignoredServices) 
     577    { 
    489578        Collection<List<Event>> onlyAcceptedServicesSequences = new LinkedList<>(); 
    490579        for (List<Event> sequence : sequences) { 
     
    493582                SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 
    494583                if (!ignoredServices.contains(eventType.getServiceName()) && 
    495                     !ignoredServices.contains(eventType.getClientName()) ) { 
     584                    !ignoredServices.contains(eventType.getClientName())) 
     585                { 
    496586                    onlyAcceptedServicesSequence.add(event); 
    497587                } 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SOAPEventType.java

    r1924 r1993  
    270270        } 
    271271    } 
     272     
     273    /** 
     274     * @return the body of the soapResponse 
     275     */ 
     276    public Element getSoapResponseBody() { 
     277        try { 
     278            return soapResponse.getSOAPBody(); 
     279        } 
     280        catch (SOAPException e) { 
     281            return null; 
     282        } 
     283    } 
    272284 
    273285    /* (non-Javadoc) 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java

    r1988 r1993  
    3838public class SimpleSOAPEventType implements IEventType { 
    3939 
     40    /** 
     41     * <p> 
     42     * Defines if this event represents an request or an response. 
     43     * </p> 
     44     *  
     45     * @author Steffen Herbold 
     46     */ 
     47    public enum CallType { 
     48        REQUEST, RESPONSE 
     49    } 
     50 
    4051    /**  */ 
    4152    private static final long serialVersionUID = 1L; 
     
    6576    /** 
    6677     * <p> 
    67      * the body of the SOAP request; storage as serialized XML string to allow object serialization 
    68      * </p> 
    69      */ 
    70     private final String soapRequestBody; 
    71      
    72     /** 
    73      * TODO 
    74      */ 
    75     private final EqualSOAPDataMap equalRequestsMap; 
     78     * the body of the SOAP message; storage as serialized XML string to allow object serialization 
     79     * </p> 
     80     */ 
     81    private final String soapMsgBody; 
     82 
     83    /** 
     84     * <p> 
     85     * defines whether this event represents a request or a response 
     86     * </p> 
     87     */ 
     88    private final CallType callType; 
     89 
     90    /** 
     91     * reference to the {@link EqualSOAPDataMap} associated with the sequence this event belongs to. 
     92     */ 
     93    private final EqualSOAPDataMap equalBodyMap; 
    7694 
    7795    /** 
     
    84102                               String serviceName, 
    85103                               String clientName, 
    86                                Element soapRequestBody) 
     104                               Element soapMsgBody) 
    87105    { 
    88         this(calledMethod, serviceName, clientName, soapRequestBody, null); 
    89     } 
    90      
    91     /** 
    92      * <p> 
    93      * Constructor. Creates a new SimpleSOAPEventType with a EqualSOAPDATAMap.  
     106        this(calledMethod, serviceName, clientName, soapMsgBody, null, CallType.REQUEST); 
     107    } 
     108 
     109    /** 
     110     * <p> 
     111     * Constructor. Creates a new SimpleSOAPEventType with a EqualSOAPDATAMap. 
    94112     * </p> 
    95113     *  
     
    98116                               String serviceName, 
    99117                               String clientName, 
    100                                Element soapRequestBody, 
     118                               Element soapMsgBody, 
    101119                               EqualSOAPDataMap equalRequestsMap) 
     120    { 
     121        this(calledMethod, serviceName, clientName, soapMsgBody, equalRequestsMap, 
     122             CallType.REQUEST); 
     123    } 
     124 
     125    /** 
     126     * <p> 
     127     * Constructor. Creates a new SimpleSOAPEventType with a EqualSOAPDATAMap. 
     128     * </p> 
     129     *  
     130     */ 
     131    public SimpleSOAPEventType(String calledMethod, 
     132                               String serviceName, 
     133                               String clientName, 
     134                               Element soapMsgBody, 
     135                               EqualSOAPDataMap equalRequestsMap, 
     136                               CallType callType) 
    102137    { 
    103138        if (calledMethod == null) { 
     
    113148        this.serviceName = serviceName; 
    114149        this.clientName = clientName; 
    115         this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody); 
    116         this.equalRequestsMap = equalRequestsMap; 
    117         if( equalRequestsMap!=null ) { 
    118             equalRequestsMap.add(this, this.soapRequestBody); 
     150        this.equalBodyMap = equalRequestsMap; 
     151        this.soapMsgBody = SOAPUtils.getSerialization(soapMsgBody); 
     152        this.callType = callType; 
     153 
     154        // this must be the last part of the constructor and only be called after all variables are 
     155        // initialized 
     156        if (equalRequestsMap != null) { 
     157            equalRequestsMap.add(this, this.soapMsgBody); 
    119158        } 
    120159    } 
     
    161200     * @return body of the SOAP request 
    162201     */ 
    163     public Element getSoapRequestBody() { 
    164         return createDOMElement(soapRequestBody); 
    165     } 
    166      
    167     /** 
    168      * <p> 
    169      * returns a randomly draw request body for the called method using {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)} 
    170      * </p> 
    171      * 
     202    public Element getSoapMsgBody() { 
     203        return createDOMElement(soapMsgBody); 
     204    } 
     205 
     206    /** 
     207     * <p> 
     208     * returns a randomly draw request body for the called method using 
     209     * {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)} 
     210     * </p> 
     211     *  
    172212     * @return randomly drawn body of the SOAP request 
    173213     */ 
    174     public Element getRandomSoapRequestBody() { 
    175         if( equalRequestsMap==null ) { 
    176             throw new RuntimeException("cannot use random mode is no request map is available; different data missing"); 
    177         } 
    178         return createDOMElement(equalRequestsMap.getRandom(this)); 
    179     } 
    180      
     214    public Element getRandomSoapMsgBody() { 
     215        if (equalBodyMap == null) { 
     216            throw new RuntimeException( 
     217                                       "cannot use random mode is no request map is available; different data missing"); 
     218        } 
     219        return createDOMElement(equalBodyMap.getRandom(this)); 
     220    } 
     221 
     222    /** 
     223     * <p> 
     224     * returns the {@link EqualSOAPDataMap} associated with this event 
     225     * </p> 
     226     *  
     227     * @return the {@link EqualSOAPDataMap} 
     228     */ 
    181229    public EqualSOAPDataMap getEqualSOAPDataMap() { 
    182         return equalRequestsMap; 
     230        return equalBodyMap; 
     231    } 
     232 
     233    public CallType getCallType() { 
     234        return callType; 
    183235    } 
    184236 
     
    190242    @Override 
    191243    public String getName() { 
    192         return "(" + serviceName + ", " + calledMethod + ")"; 
     244        return "(" + callType + ":" + clientName + "->" + serviceName + ", " + calledMethod + ")"; 
    193245    } 
    194246 
     
    204256        } 
    205257        else if (obj instanceof SimpleSOAPEventType) { 
    206             return HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) && 
     258            return callType.equals(((SimpleSOAPEventType) obj).callType) && 
     259                HTTPUtils.equals(calledMethod, ((SimpleSOAPEventType) obj).calledMethod) && 
    207260                HTTPUtils.equals(serviceName, ((SimpleSOAPEventType) obj).serviceName) && 
    208261                HTTPUtils.equals(clientName, ((SimpleSOAPEventType) obj).clientName); 
     
    220273    @Override 
    221274    public int hashCode() { 
    222         int hashCode = calledMethod.hashCode() + serviceName.hashCode() + clientName.hashCode(); 
    223         return hashCode; 
     275        return callType.hashCode() + calledMethod.hashCode() + serviceName.hashCode() + 
     276            clientName.hashCode(); 
    224277    } 
    225278 
     
    231284    @Override 
    232285    public String toString() { 
    233         return "SimpleSOAPEventType(" + serviceName + ", " + calledMethod + ")"; 
     286        return "SimpleSOAPEventType" + getName(); 
    234287    } 
    235288 
     
    243296        } 
    244297    } 
    245 // 
    246 //    /** 
    247 //     * <p> 
    248 //     * Determines how getSoapRequestBody works. 
    249 //     * <ul> 
    250 //     * <li>LOCALEVENT: returns the request body of the event type itself</li> 
    251 //     * <li>RANDOM: returns a randomly draw request body for the called method using 
    252 //     * {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)}. 
    253 //     * </ul> 
    254 //     * </p> 
    255 //     *  
    256 //     * @author Steffen Herbold 
    257 //     */ 
    258 //    public static enum RequestBodyMode { 
    259 //        LOCALEVENT, RANDOM 
    260 //    } 
    261298} 
  • trunk/autoquest-plugin-uml-test/src/test/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtilsTest.java

    r1992 r1993  
    385385 
    386386        sequences = SOAPUtils.removeNonSOAPEvents(sequences); 
    387         sequences = SOAPUtils.sortSequences(sequences, SequenceOrder.REQUEST); 
    388         sequences = SOAPUtils.convertToSimpleSOAPEvent(sequences, true); 
     387        sequences = SOAPUtils.sortAndConvertSequences(sequences, true, true); 
    389388        sequences = SOAPUtils.normalizeOperationNames(sequences, properties 
    390389                    .getProperty("methodName.prefixToRemove"), properties 
  • trunk/autoquest-plugin-uml-test/src/test/resources/ita_imported_properties.prop

    r1979 r1993  
    2424testcases.minlenght = 1 
    2525testcases.maxlength = 1 
     26testcases.data.random = false 
    2627 
  • trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java

    r1988 r1993  
    10391039                                                 String prefix) 
    10401040    { 
    1041         org.w3c.dom.Element requestBody = SOAPUtils.getSoapRequestBodyFromEvent(event, useRandomRequestBodies); 
     1041        org.w3c.dom.Element requestBody = SOAPUtils.getSoapBodyFromEvent(event, useRandomRequestBodies); 
    10421042        Package instSpecPkg = null; 
    10431043 
Note: See TracChangeset for help on using the changeset viewer.