Changeset 1988 for trunk


Ignore:
Timestamp:
07/07/15 08:36:28 (9 years ago)
Author:
sherbold
Message:
  • updated EqualSOAPDataMap: not a singleton anymore, now each event has a reference to the map. the map is created when the SOAPEvents are converted to SimpleSOAPEvents using the appropriate method from the SOAPUtils
  • the logic for deciding if random SOAP requests are selected or the one of the event itself was changed within the SimpleSOAPEvents. Now methods for both are offered and the caller has to decide which method to choose
  • the test case generation in the model utils now has a parameter to decide if random data or the data of the SimpleSOAPEvents is used
Location:
trunk
Files:
1 deleted
5 edited

Legend:

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

    r1987 r1988  
    4646        parser.parseFile(new File(ClassLoader.getSystemResource("testParseFile_3_logfile.log") 
    4747            .getFile())); 
    48         Collection<List<Event>> events = parser.getSequences(); 
     48        Collection<List<Event>> sequences = parser.getSequences(); 
    4949 
    50         assertNotNull(events); 
    51         assertEquals(1, events.size()); 
     50        assertNotNull(sequences); 
     51        assertFalse(sequences.isEmpty()); 
    5252 
    53         List<Event> sequence = events.iterator().next(); 
     53        Collection<List<Event>> newSequences = SOAPUtils.convertToSimpleSOAPEvent(sequences, false); 
     54         
     55        assertNotNull(newSequences); 
     56        assertEquals(sequences.size(), newSequences.size()); 
    5457 
    55         List<Event> newSequence = SOAPUtils.convertToSimpleSOAPEvent(sequence, false); 
    56  
    57         assertNotNull(newSequence); 
    58         assertEquals(sequence.size(), newSequence.size()); 
    59  
    60         Iterator<Event> oldSeqIter = sequence.iterator(); 
    61         Iterator<Event> newSeqIter = newSequence.iterator(); 
    62  
    63         while (oldSeqIter.hasNext()) { 
    64             Event oldEvent = oldSeqIter.next(); 
    65             Event newEvent = newSeqIter.next(); 
    66  
    67             if (oldEvent.getType() instanceof SOAPEventType) { 
    68                 assertTrue(newEvent.getType() instanceof SimpleSOAPEventType); 
    69                 SOAPEventType oldEventType = (SOAPEventType) oldEvent.getType(); 
    70                 SimpleSOAPEventType newEventType = (SimpleSOAPEventType) newEvent.getType(); 
    71                 assertEquals(oldEventType.getCalledMethod(), newEventType.getCalledMethod()); 
    72                 assertEquals(oldEventType.getServiceName(), newEventType.getServiceName()); 
    73                 assertEquals(oldEventType.getClientName(), newEventType.getClientName()); 
    74                 assertNull(newEvent.getTarget()); 
    75             } 
    76             else { 
    77                 assertSame(oldEvent, newEvent); 
     58        // compare sequences 
     59        Iterator<List<Event>> oldIter = sequences.iterator(); 
     60        Iterator<List<Event>> newIter = newSequences.iterator(); 
     61         
     62        while( oldIter.hasNext() ) { 
     63            Iterator<Event> oldSeqIter = oldIter.next().iterator(); 
     64            Iterator<Event> newSeqIter = newIter.next().iterator(); 
     65     
     66            while (oldSeqIter.hasNext()) { 
     67                Event oldEvent = oldSeqIter.next(); 
     68                Event newEvent = newSeqIter.next(); 
     69     
     70                if (oldEvent.getType() instanceof SOAPEventType) { 
     71                    assertTrue(newEvent.getType() instanceof SimpleSOAPEventType); 
     72                    SOAPEventType oldEventType = (SOAPEventType) oldEvent.getType(); 
     73                    SimpleSOAPEventType newEventType = (SimpleSOAPEventType) newEvent.getType(); 
     74                    assertEquals(oldEventType.getCalledMethod(), newEventType.getCalledMethod()); 
     75                    assertEquals(oldEventType.getServiceName(), newEventType.getServiceName()); 
     76                    assertEquals(oldEventType.getClientName(), newEventType.getClientName()); 
     77                    assertNull(newEvent.getTarget()); 
     78                } 
     79                else { 
     80                    assertSame(oldEvent, newEvent); 
     81                } 
    7882            } 
    7983        } 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/SOAPUtils.java

    r1983 r1988  
    1717import java.io.StringWriter; 
    1818import java.util.ArrayList; 
     19import java.util.Collection; 
    1920import java.util.Iterator; 
    2021import java.util.LinkedList; 
     
    3435 
    3536import de.ugoe.cs.autoquest.eventcore.Event; 
     37import de.ugoe.cs.autoquest.plugin.http.eventcore.EqualSOAPDataMap; 
    3638import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 
    3739import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; 
     
    5355     * </p> 
    5456     *  
    55      * @param sequence 
    56      *            sequence where the events are replaced 
     57     * @param sequences 
     58     *            sequences where the events are replaced 
    5759     * @param keepOnlySOAPEvents 
    5860     *            if true, all events that are not of SOAPEventType or SimpleSOAPEventType are 
    5961     *            removed 
    60      * @return sequence with {@link SimpleSOAPEventType}s instead of {@link SOAPEventType}s 
    61      */ 
    62     public static List<Event> convertToSimpleSOAPEvent(List<Event> sequence, 
     62     * @return sequences with {@link SimpleSOAPEventType}s instead of {@link SOAPEventType}s 
     63     */ 
     64    public static Collection<List<Event>> convertToSimpleSOAPEvent(Collection<List<Event>> sequences, 
    6365                                                       boolean keepOnlySOAPEvents) 
    6466    { 
    65         List<Event> newSequence = null; 
    66         if (sequence != null) { 
    67             newSequence = new LinkedList<>(); 
    68             for (Event event : sequence) { 
    69                 if (event.getType() instanceof SOAPEventType) { 
    70                     SOAPEventType eventType = (SOAPEventType) event.getType(); 
    71                     newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(), 
    72                                                                       eventType.getServiceName(), 
    73                                                                       eventType.getClientName(), 
    74                                                                       eventType 
    75                                                                           .getSoapRequestBody()))); 
    76                 } 
    77                 else { 
    78                     if (!keepOnlySOAPEvents || event.getType() instanceof SimpleSOAPEventType) { 
    79                         newSequence.add(event); 
     67        Collection<List<Event>> newSequences = new LinkedList<>(); 
     68        EqualSOAPDataMap equalSOAPDataMap = new EqualSOAPDataMap(); 
     69        for( List<Event> sequence : sequences ) { 
     70            List<Event> newSequence = null; 
     71            if (sequence != null) { 
     72                newSequence = new LinkedList<>(); 
     73                for (Event event : sequence) { 
     74                    if (event.getType() instanceof SOAPEventType) { 
     75                        SOAPEventType eventType = (SOAPEventType) event.getType(); 
     76                        newSequence.add(new Event(new SimpleSOAPEventType(eventType.getCalledMethod(), 
     77                                                                          eventType.getServiceName(), 
     78                                                                          eventType.getClientName(), 
     79                                                                          eventType 
     80                                                                              .getSoapRequestBody(), 
     81                                                                          equalSOAPDataMap))); 
     82                    } 
     83                    else { 
     84                        if (!keepOnlySOAPEvents || event.getType() instanceof SimpleSOAPEventType) { 
     85                            newSequence.add(event); 
     86                        } 
    8087                    } 
    8188                } 
    8289            } 
    83         } 
    84         return newSequence; 
    85     } 
    86  
     90            newSequences.add(newSequence); 
     91        } 
     92        return newSequences; 
     93    } 
     94     
    8795    /** 
    8896     * <p> 
     
    182190     */ 
    183191    public static Element getSoapRequestBodyFromEvent(Event event) { 
     192        return getSoapRequestBodyFromEvent(event, false); 
     193    } 
     194     
     195    /** 
     196     * <p> 
     197     * Helper function to get the body of a SOAP request. 
     198     * </p> 
     199     *  
     200     * @param event 
     201     *            event for which the SOAP request body is retrieved 
     202     * @param useRandomRequestBodies 
     203     *            defines is random request bodies are used or the body of the associated event 
     204     * @return body of the SOAP event 
     205     */ 
     206    public static Element getSoapRequestBodyFromEvent(Event event, boolean useRandomRequestBodies) { 
    184207        Element requestBody = null; 
    185208        if (event.getType() instanceof SOAPEventType) { 
     
    187210        } 
    188211        else if (event.getType() instanceof SimpleSOAPEventType) { 
    189             requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 
     212            if( useRandomRequestBodies ) { 
     213                requestBody = ((SimpleSOAPEventType) event.getType()).getRandomSoapRequestBody(); 
     214            } else { 
     215                requestBody = ((SimpleSOAPEventType) event.getType()).getSoapRequestBody(); 
     216            } 
    190217        } 
    191218        return requestBody; 
     
    295322     * </p> 
    296323     * 
    297      * @param sequence sequences where the operation names are normalized 
    298      */ 
    299     public static List<Event> normalizeOperationNames(List<Event> sequence, String prefixToRemove, String suffixToRemove) { 
    300         List<Event> normalizedSequence = new LinkedList<>(); 
    301         for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
    302             Event event = eventIter.next(); 
    303             if ((event.getType() instanceof SimpleSOAPEventType)) { 
    304                 SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 
    305                 String methodName = eventType.getCalledMethod(); 
    306                 if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) { 
    307                     methodName = methodName.substring(prefixToRemove.length(), methodName.length()); 
    308                     // remove prefix 
    309                 }  
    310                 if( suffixToRemove!=null && methodName.endsWith(suffixToRemove) ) { 
    311                     methodName = methodName.substring(0, methodName.length()-suffixToRemove.length()); 
     324     * @param sequences sequences where the operation names are normalized 
     325     */ 
     326    public static Collection<List<Event>> normalizeOperationNames(Collection<List<Event>> sequences, String prefixToRemove, String suffixToRemove) { 
     327        Collection<List<Event>> normalizedSequences = new LinkedList<>(); 
     328        for(List<Event> sequence : sequences ) { 
     329            List<Event> normalizedSequence = new LinkedList<>(); 
     330            for (Iterator<Event> eventIter = sequence.iterator(); eventIter.hasNext();) { 
     331                Event event = eventIter.next(); 
     332                if ((event.getType() instanceof SimpleSOAPEventType)) { 
     333                    SimpleSOAPEventType eventType = (SimpleSOAPEventType) event.getType(); 
     334                    String methodName = eventType.getCalledMethod(); 
     335                    if( prefixToRemove!=null && methodName.startsWith(prefixToRemove) ) { 
     336                        methodName = methodName.substring(prefixToRemove.length(), methodName.length()); 
     337                        // remove prefix 
     338                    }  
     339                    if( suffixToRemove!=null && methodName.endsWith(suffixToRemove) ) { 
     340                        methodName = methodName.substring(0, methodName.length()-suffixToRemove.length()); 
     341                    } 
     342                    event = new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), eventType.getClientName(), eventType.getSoapRequestBody(), eventType.getEqualSOAPDataMap()), event.getTarget()); 
    312343                } 
    313                 event = new Event(new SimpleSOAPEventType(methodName, eventType.getServiceName(), eventType.getClientName(), eventType.getSoapRequestBody()), event.getTarget()); 
    314             } 
    315             normalizedSequence.add(event); 
    316         } 
    317         return normalizedSequence; 
     344                normalizedSequence.add(event); 
     345            } 
     346            normalizedSequences.add(normalizedSequence); 
     347        } 
     348        return normalizedSequences; 
    318349    } 
    319350 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/EqualSOAPDataMap.java

    r1986 r1988  
    1515package de.ugoe.cs.autoquest.plugin.http.eventcore; 
    1616 
    17 import java.io.IOException; 
    18 import java.io.ObjectInputStream; 
    19 import java.io.ObjectOutputStream; 
    2017import java.io.Serializable; 
    2118import java.util.Collections; 
     
    3835    /**  */ 
    3936    private static final long serialVersionUID = 1L; 
    40  
    41     /** 
    42      * Singleton. Handle to only instance of this class 
    43      */ 
    44     transient private static EqualSOAPDataMap INSTANCE = new EqualSOAPDataMap(); 
    4537     
    4638    /** 
     
    5244     * random number generator for picking a random request body 
    5345     */ 
    54     transient private final Random random; 
    55      
    56     /** 
    57      * <p> 
    58      * return the instance of the class 
    59      * </p> 
    60      * 
    61      * @return 
    62      */ 
    63     public static EqualSOAPDataMap getInstance() { 
    64         return INSTANCE; 
    65     } 
    66      
    67     private EqualSOAPDataMap() { 
    68         // private constructor to avoid initialization 
    69         random = new Random(); 
    70     } 
    71      
    72     /** 
    73      * <p> 
    74      * Manual serialization of the object. Necessary to guarantee the singleton 
    75      * property. 
    76      * </p> 
    77      *  
    78      * @param s 
    79      *            output stream for the serialization 
    80      * @throws IOException 
    81      *             thrown if there is problem writing to the output stream 
    82      */ 
    83     private void writeObject(ObjectOutputStream s) throws IOException { 
    84             s.defaultWriteObject(); 
    85             s.writeObject(soapRequestBodies); 
    86     } 
     46    private final Random random = new Random(); 
    8747 
    8848    /** 
    8949     * <p> 
    90      * Manual de-serialization of the object. Necessary to guarantee the 
    91      * singleton property. 
    92      *  
    93      * @param s 
    94      *            input stream for the de-serialization 
    95      * @throws IOException 
    96      *             thrown if there is problem reading from the input stream 
    97      * @throws ClassNotFoundException 
    98      *             thrown if there is a problem reading from the input stream 
     50     * Default constructor.  
     51     * </p> 
    9952     */ 
    100     @SuppressWarnings("unchecked") 
    101     private void readObject(ObjectInputStream s) throws IOException, 
    102                     ClassNotFoundException { 
    103             s.defaultReadObject(); 
    104             if (INSTANCE == null) { 
    105                 INSTANCE = new EqualSOAPDataMap(); 
    106             } 
    107             INSTANCE.soapRequestBodies = (Map<SimpleSOAPEventType, ListOrderedSet<String>>) s.readObject(); 
     53    public EqualSOAPDataMap() { 
     54         
    10855    } 
    109  
    110     /** 
    111      * <p> 
    112      * Manual de-serialization to guarantee the singleton property. 
    113      * </p> 
    114      *  
    115      * @return instance of the container 
    116      */ 
    117     private Object readResolve() { 
    118             return INSTANCE; 
    119     } 
    120  
     56     
    12157    /** 
    12258     * <p> 
     
    175111        soapRequestBodies = new HashMap<>(); 
    176112    } 
     113     
     114    /** 
     115     * <p> 
     116     * returns is the current data map is empty 
     117     * </p> 
     118     * 
     119     * @return true if empty; false otherwise 
     120     */ 
     121    public boolean isEmpty() { 
     122        return soapRequestBodies.isEmpty(); 
     123    } 
    177124} 
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java

    r1987 r1988  
    4242 
    4343    /** 
    44      * see {@link RequestBodyMode} 
    45      */ 
    46     private static RequestBodyMode requestBodyMode = RequestBodyMode.LOCALEVENT; 
    47  
    48     /** 
    4944     * <p> 
    5045     * the SOAP method called in this request 
     
    7469     */ 
    7570    private final String soapRequestBody; 
     71     
     72    /** 
     73     * TODO 
     74     */ 
     75    private final EqualSOAPDataMap equalRequestsMap; 
    7676 
    7777    /** 
     
    8686                               Element soapRequestBody) 
    8787    { 
     88        this(calledMethod, serviceName, clientName, soapRequestBody, null); 
     89    } 
     90     
     91    /** 
     92     * <p> 
     93     * Constructor. Creates a new SimpleSOAPEventType with a EqualSOAPDATAMap.  
     94     * </p> 
     95     *  
     96     */ 
     97    public SimpleSOAPEventType(String calledMethod, 
     98                               String serviceName, 
     99                               String clientName, 
     100                               Element soapRequestBody, 
     101                               EqualSOAPDataMap equalRequestsMap) 
     102    { 
    88103        if (calledMethod == null) { 
    89104            throw new IllegalArgumentException("called method must not be null"); 
     
    99114        this.clientName = clientName; 
    100115        this.soapRequestBody = SOAPUtils.getSerialization(soapRequestBody); 
    101         EqualSOAPDataMap.getInstance().add(this, this.soapRequestBody); 
     116        this.equalRequestsMap = equalRequestsMap; 
     117        if( equalRequestsMap!=null ) { 
     118            equalRequestsMap.add(this, this.soapRequestBody); 
     119        } 
    102120    } 
    103121 
     
    144162     */ 
    145163    public Element getSoapRequestBody() { 
    146         String requestBody; 
    147         switch (requestBodyMode) 
    148         { 
    149             case LOCALEVENT: 
    150                 requestBody = soapRequestBody; 
    151                 break; 
    152             case RANDOM: 
    153                 requestBody = EqualSOAPDataMap.getInstance().getRandom(this); 
    154                 break; 
    155             default: 
    156                 throw new RuntimeException("undefined RequestBodyMode"); 
    157         } 
    158         if (requestBody == null) { 
    159             System.err.println("foobar" + this); 
    160             System.err.println(EqualSOAPDataMap.getInstance().getAll(this)); 
    161         } 
    162         try { 
    163             return DocumentBuilderFactory.newInstance().newDocumentBuilder() 
    164                 .parse(new ByteArrayInputStream(requestBody.getBytes())).getDocumentElement(); 
    165         } 
    166         catch (SAXException | IOException | ParserConfigurationException e) { 
    167             return null; 
    168         } 
     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     * 
     172     * @return randomly drawn body of the SOAP request 
     173     */ 
     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     
     181    public EqualSOAPDataMap getEqualSOAPDataMap() { 
     182        return equalRequestsMap; 
    169183    } 
    170184 
     
    220234    } 
    221235 
    222     /** 
    223      * <p> 
    224      * returns the current {@link RequestBodyMode} 
    225      * </p> 
    226      *  
    227      * @return the requestBodyMode 
    228      */ 
    229     public static RequestBodyMode getRequestBodyMode() { 
    230         return requestBodyMode; 
    231     } 
    232  
    233     /** 
    234      * <p> 
    235      * sets the {@link RequestBodyMode} 
    236      * </p> 
    237      *  
    238      * @param new requestBodyMode 
    239      */ 
    240     public static void setRequestBodyMode(RequestBodyMode requestBodyMode) { 
    241         SimpleSOAPEventType.requestBodyMode = requestBodyMode; 
    242     } 
    243  
    244     /** 
    245      * <p> 
    246      * Determines how getSoapRequestBody works. 
    247      * <ul> 
    248      * <li>LOCALEVENT: returns the request body of the event type itself</li> 
    249      * <li>RANDOM: returns a randomly draw request body for the called method using 
    250      * {@link EqualSOAPDataMap#getRandom(SimpleSOAPEventType)}. 
    251      * </ul> 
    252      * </p> 
    253      *  
    254      * @author Steffen Herbold 
    255      */ 
    256     public static enum RequestBodyMode { 
    257         LOCALEVENT, RANDOM 
    258     } 
     236    private Element createDOMElement(String requestBody) { 
     237        try { 
     238            return DocumentBuilderFactory.newInstance().newDocumentBuilder() 
     239                .parse(new ByteArrayInputStream(requestBody.getBytes())).getDocumentElement(); 
     240        } 
     241        catch (SAXException | IOException | ParserConfigurationException e) { 
     242            return null; 
     243        } 
     244    } 
     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//    } 
    259261} 
  • trunk/autoquest-plugin-uml/src/main/java/de/ugoe/cs/autoquest/plugin/uml/UMLUtils.java

    r1978 r1988  
    425425     *            Name of the test context that should be used. If this value is null, the first 
    426426     *            test context found is used. 
     427     * @param useRandomRequestBodies 
     428     *            defines is random request bodies are used or the body of the associated event 
    427429     */ 
    428430    public static Interaction createInteractionFromEventSequence(List<Event> sequence, 
    429431                                                                 Model model, 
    430432                                                                 String interactionName, 
    431                                                                  String testContextName) 
     433                                                                 String testContextName, 
     434                                                                 boolean useRandomRequestBodies) 
    432435    { 
    433436        final Component testContext = fetchTestContext(model, testContextName); 
     
    546549                Message callMessage = interaction.createMessage(prefix + "call"); 
    547550                callMessage.setSignature(calledOperation); 
    548                 setCallMessageParameters(callMessage, calledOperation, event, prefix); 
     551                setCallMessageParameters(callMessage, calledOperation, event, useRandomRequestBodies, prefix); 
    549552                callMessage.setConnector(connector); 
    550553                callMessage.setSendEvent(callSendFragment); 
     
    10251028     * @param event 
    10261029     *            event that provides the parameters; in case of null, default values are assumed 
     1030     * @param useRandomRequestBodies 
     1031     *            defines is random request bodies are used or the body of the associated event 
    10271032     * @param prefix 
    10281033     *            prefix of the call message; used to create good warnings and debugging information 
     
    10311036                                                 Operation calledOperation, 
    10321037                                                 Event event, 
     1038                                                 boolean useRandomRequestBodies, 
    10331039                                                 String prefix) 
    10341040    { 
    1035         org.w3c.dom.Element requestBody = SOAPUtils.getSoapRequestBodyFromEvent(event); 
     1041        org.w3c.dom.Element requestBody = SOAPUtils.getSoapRequestBodyFromEvent(event, useRandomRequestBodies); 
    10361042        Package instSpecPkg = null; 
    10371043 
Note: See TracChangeset for help on using the changeset viewer.