Ignore:
Timestamp:
08/16/12 17:08:27 (12 years ago)
Author:
sherbold
Message:
  • adapted PHP plugin event structure to new event structure
Location:
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/eventcore
Files:
2 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/eventcore/WebRequest.java

    r434 r554  
     1 
    12package de.ugoe.cs.quest.plugin.php.eventcore; 
    23 
     
    89/** 
    910 * <p> 
    10  * Contains all information related to a web request, i.e., the path, the POST 
    11  * variables and the GET variables. The generated replay are for the command 
    12  * line tool {@code curl}. The requests do not contain correct values for the 
    13  * POST and GET request. Instead, only the parameters that are part of the 
    14  * requests are added and the values of the parameters are 
    15  * DATA_$PARAMNAME$_DATA, where $PARAMNAME$ is the upper case string of the 
    16  * parameter name. This allows test data generators to insert concrete values, 
    17  * as EventBench does not include a test data generator for web software. 
     11 * Contains all information related to a web request, i.e., the path, the POST variables and the GET 
     12 * variables. The generated replay are for the command line tool {@code curl}. The requests do not 
     13 * contain correct values for the POST and GET request. Instead, only the parameters that are part 
     14 * of the requests are added and the values of the parameters are DATA_$PARAMNAME$_DATA, where 
     15 * $PARAMNAME$ is the upper case string of the parameter name. This allows test data generators to 
     16 * insert concrete values, as EventBench does not include a test data generator for web software. 
    1817 * </p> 
    1918 *  
     
    2322public class WebRequest implements IReplayable { 
    2423 
    25         /** 
    26         * <p> 
    27         * Id for object serialization. 
    28         * </p> 
    29         */ 
    30         private static final long serialVersionUID = 1L; 
     24    /** 
     25    * <p> 
     26    * Id for object serialization. 
     27    * </p> 
     28    */ 
     29    private static final long serialVersionUID = 1L; 
    3130 
    32         /** 
    33         * <p> 
    34         * POST variables of the web request. 
    35         * </p> 
    36         */ 
    37         List<String> postVars; 
     31    /** 
     32    * <p> 
     33    * POST variables of the web request. 
     34    * </p> 
     35    */ 
     36    List<String> postVars; 
    3837 
    39         /** 
    40         * <p> 
    41         * GET variables of the web request. 
    42         * </p> 
    43         */ 
    44         List<String> getVars; 
     38    /** 
     39    * <p> 
     40    * GET variables of the web request. 
     41    * </p> 
     42    */ 
     43    List<String> getVars; 
    4544 
    46         /** 
    47         * <p> 
    48         * URI of the web request. 
    49         * </p> 
    50         */ 
    51         String targetUri; 
     45    /** 
     46    * <p> 
     47    * URI of the web request. 
     48    * </p> 
     49    */ 
     50    String targetUri; 
    5251 
    53         /** 
    54         * <p> 
    55         * URL of the server. 
    56         * </p> 
    57         */ 
    58         String serverUrl; 
     52    /** 
     53    * <p> 
     54    * URL of the server. 
     55    * </p> 
     56    */ 
     57    String serverUrl; 
    5958 
    60         /** 
    61          * <p> 
    62          * Constructor. Creates a new WebRequest. 
    63          * </p> 
    64          *  
    65          * @param uri 
    66          *            URI of the request 
    67          * @param postVars 
    68          *            POST variables of the request 
    69          * @param getVars 
    70          *            GET variables of the request 
    71          */ 
    72         public WebRequest(String url, String uri, List<String> postVars, 
    73                         List<String> getVars) { 
    74                 serverUrl = url; 
    75                 targetUri = uri; 
    76                 this.postVars = new ArrayList<String>(postVars); // defensive copy 
    77                 this.getVars = new ArrayList<String>(getVars); 
    78         } 
     59    /** 
     60     * <p> 
     61     * Constructor. Creates a new WebRequest. 
     62     * </p> 
     63     *  
     64     * @param uri 
     65     *            URI of the request 
     66     * @param postVars 
     67     *            POST variables of the request 
     68     * @param getVars 
     69     *            GET variables of the request 
     70     */ 
     71    public WebRequest(String url, String uri, List<String> postVars, List<String> getVars) { 
     72        serverUrl = url; 
     73        targetUri = uri; 
     74        this.postVars = new ArrayList<String>(postVars); // defensive copy 
     75        this.getVars = new ArrayList<String>(getVars); 
     76    } 
    7977 
    80         /* 
    81         * (non-Javadoc) 
    82         *  
    83         * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 
    84         */ 
    85         @Override 
    86         public String getReplay() { 
    87                 StringBuilder builder = new StringBuilder(); 
    88                 builder.append("curl"); 
    89                 if (!postVars.isEmpty()) { 
    90                         boolean isFirstPost = true; 
    91                         for (String postVar : postVars) { 
    92                                 if (isFirstPost) { 
    93                                         builder.append(" --data \""); 
    94                                         isFirstPost = false; 
    95                                 } else { 
    96                                         builder.append('&'); 
    97                                 } 
    98                                 builder.append(postVar + "=DATA_" + postVar.toUpperCase() 
    99                                                 + "_DATA"); 
    100                         } 
    101                         builder.append('\"'); 
    102                 } 
    103                 builder.append(' '); 
    104                 if (serverUrl != null) { 
    105                         builder.append(serverUrl); 
    106                 } 
    107                 builder.append(targetUri); 
    108                 if (!getVars.isEmpty()) { 
    109                         boolean isFirstGet = true; 
    110                         for (String getVar : getVars) { 
    111                                 if (isFirstGet) { 
    112                                         builder.append('?'); 
    113                                         isFirstGet = false; 
    114                                 } else { 
    115                                         builder.append('&'); 
    116                                 } 
    117                                 builder.append(getVar + "=DATA_" + getVar.toUpperCase() 
    118                                                 + "_DATA"); 
    119                         } 
    120                 } 
    121                 return builder.toString(); 
    122         } 
     78    /* 
     79    * (non-Javadoc) 
     80    *  
     81    * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 
     82    */ 
     83    @Override 
     84    public String getReplay() { 
     85        StringBuilder builder = new StringBuilder(); 
     86        builder.append("curl"); 
     87        if (!postVars.isEmpty()) { 
     88            boolean isFirstPost = true; 
     89            for (String postVar : postVars) { 
     90                if (isFirstPost) { 
     91                    builder.append(" --data \""); 
     92                    isFirstPost = false; 
     93                } 
     94                else { 
     95                    builder.append('&'); 
     96                } 
     97                builder.append(postVar + "=DATA_" + postVar.toUpperCase() + "_DATA"); 
     98            } 
     99            builder.append('\"'); 
     100        } 
     101        builder.append(' '); 
     102        if (serverUrl != null) { 
     103            builder.append(serverUrl); 
     104        } 
     105        builder.append(targetUri); 
     106        if (!getVars.isEmpty()) { 
     107            boolean isFirstGet = true; 
     108            for (String getVar : getVars) { 
     109                if (isFirstGet) { 
     110                    builder.append('?'); 
     111                    isFirstGet = false; 
     112                } 
     113                else { 
     114                    builder.append('&'); 
     115                } 
     116                builder.append(getVar + "=DATA_" + getVar.toUpperCase() + "_DATA"); 
     117            } 
     118        } 
     119        return builder.toString(); 
     120    } 
    123121 
    124         /* 
    125          * (non-Javadoc) 
    126          *  
    127          * @see de.ugoe.cs.quest.eventcore.IReplayable#getTarget() 
    128          */ 
    129         @Override 
    130         public String getTarget() { 
    131                 return targetUri; 
    132         } 
     122    /** 
     123     * <p> 
     124     * Two {@link WebRequest}s are equal, if their {@link #targetUri}, {@link #postVars}, and 
     125     * {@link #getVars} are equal. 
     126     * </p> 
     127     *  
     128     * @see java.lang.Object#equals(java.lang.Object) 
     129     */ 
     130    @Override 
     131    public boolean equals(Object other) { 
     132        if (this == other) { 
     133            return true; 
     134        } 
     135        if (other instanceof WebRequest) { 
     136            return targetUri.equals(((WebRequest) other).targetUri) && 
     137                postVars.equals(((WebRequest) other).postVars) && 
     138                getVars.equals(((WebRequest) other).getVars); 
     139        } 
     140        return false; 
     141    } 
    133142 
    134         /** 
    135          * <p> 
    136          * Two {@link WebRequest}s are equal, if their {@link #targetUri}, 
    137          * {@link #postVars}, and {@link #getVars} are equal. 
    138          * </p> 
    139          *  
    140          * @see java.lang.Object#equals(java.lang.Object) 
    141          */ 
    142         @Override 
    143         public boolean equals(Object other) { 
    144                 if (this == other) { 
    145                         return true; 
    146                 } 
    147                 if (other instanceof WebRequest) { 
    148                         return targetUri.equals(((WebRequest) other).targetUri) 
    149                                         && postVars.equals(((WebRequest) other).postVars) 
    150                                         && getVars.equals(((WebRequest) other).getVars); 
    151                 } 
    152                 return false; 
    153         } 
     143    /* 
     144     * (non-Javadoc) 
     145     *  
     146     * @see java.lang.Object#hashCode() 
     147     */ 
     148    @Override 
     149    public int hashCode() { 
     150        int multiplier = 17; 
     151        int hash = 42; 
    154152 
    155         /* 
    156          * (non-Javadoc) 
    157          *  
    158          * @see java.lang.Object#hashCode() 
    159          */ 
    160         @Override 
    161         public int hashCode() { 
    162                 int multiplier = 17; 
    163                 int hash = 42; 
     153        hash = multiplier * hash + targetUri.hashCode(); 
     154        hash = multiplier * hash + postVars.hashCode(); 
     155        hash = multiplier * hash + getVars.hashCode(); 
    164156 
    165                 hash = multiplier * hash + targetUri.hashCode(); 
    166                 hash = multiplier * hash + postVars.hashCode(); 
    167                 hash = multiplier * hash + getVars.hashCode(); 
    168  
    169                 return hash; 
    170         } 
     157        return hash; 
     158    } 
    171159 
    172160} 
Note: See TracChangeset for help on using the changeset viewer.