- Timestamp:
- 08/16/12 17:08:27 (12 years ago)
- 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 1 2 package de.ugoe.cs.quest.plugin.php.eventcore; 2 3 … … 8 9 /** 9 10 * <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. 18 17 * </p> 19 18 * … … 23 22 public class WebRequest implements IReplayable { 24 23 25 26 27 28 29 30 24 /** 25 * <p> 26 * Id for object serialization. 27 * </p> 28 */ 29 private static final long serialVersionUID = 1L; 31 30 32 33 34 35 36 37 31 /** 32 * <p> 33 * POST variables of the web request. 34 * </p> 35 */ 36 List<String> postVars; 38 37 39 40 41 42 43 44 38 /** 39 * <p> 40 * GET variables of the web request. 41 * </p> 42 */ 43 List<String> getVars; 45 44 46 47 48 49 50 51 45 /** 46 * <p> 47 * URI of the web request. 48 * </p> 49 */ 50 String targetUri; 52 51 53 54 55 56 57 58 52 /** 53 * <p> 54 * URL of the server. 55 * </p> 56 */ 57 String serverUrl; 59 58 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 } 79 77 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 } else { 96 builder.append('&'); 97 } 98 builder.append(postVar + "=DATA_" + postVar.toUpperCase() 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 } else { 115 builder.append('&'); 116 } 117 builder.append(getVar + "=DATA_" + getVar.toUpperCase() 118 119 120 121 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 } 123 121 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 } 133 142 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; 154 152 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(); 164 156 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 } 171 159 172 160 }
Note: See TracChangeset
for help on using the changeset viewer.