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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.