Changeset 1906
- Timestamp:
- 03/11/15 13:56:46 (10 years ago)
- Location:
- trunk
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/eventcore/SOAPEventTypeTest.java
r1635 r1906 15 15 package de.ugoe.cs.autoquest.http.eventcore; 16 16 17 import static org.junit.Assert.assertEquals; 18 19 import java.math.BigInteger; 20 import java.util.Properties; 21 22 import javax.xml.soap.MessageFactory; 23 import javax.xml.soap.SOAPMessage; 24 17 25 import nl.jqno.equalsverifier.EqualsVerifier; 18 26 import nl.jqno.equalsverifier.Warning; … … 21 29 22 30 import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; 31 import de.ugoe.cs.autoquest.plugin.http.logdata.Address; 32 import de.ugoe.cs.autoquest.plugin.http.logdata.HttpExchange; 33 import de.ugoe.cs.autoquest.plugin.http.logdata.HttpRequest; 23 34 24 35 /** 25 * <p> 26 * TODO comment 27 * </p> 28 * 36 * 29 37 * @author Patrick Harms 30 38 */ 31 public class SOAPEventTest { 32 39 public class SOAPEventTypeTest { 40 41 /** 42 * 43 */ 33 44 @Test 34 45 public void test_EqualsContract_01() { … … 37 48 } 38 49 50 /** 51 * 52 */ 53 @Test 54 public void test_ClientName_01() throws Exception { 55 HttpExchange exchange = createDummyExchange(); 56 SOAPMessage dummyMessage = createDummySOAPMessage(); 57 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, null); 58 59 assertEquals("sender:1234", fixture.getClientName()); 60 } 61 62 /** 63 * 64 */ 65 @Test 66 public void test_ClientName_02() throws Exception { 67 HttpExchange exchange = createDummyExchange(); 68 SOAPMessage dummyMessage = createDummySOAPMessage(); 69 Properties properties = new Properties(); 70 71 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 72 73 assertEquals("sender:1234", fixture.getClientName()); 74 } 75 76 /** 77 * 78 */ 79 @Test 80 public void test_ClientName_03() throws Exception { 81 HttpExchange exchange = createDummyExchange(); 82 SOAPMessage dummyMessage = createDummySOAPMessage(); 83 Properties properties = new Properties(); 84 properties.put("clientName.sender.sender", "replacedSender"); 85 86 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 87 88 assertEquals("replacedSender", fixture.getClientName()); 89 } 90 91 /** 92 * 93 */ 94 @Test 95 public void test_ClientName_04() throws Exception { 96 HttpExchange exchange = createDummyExchange(); 97 SOAPMessage dummyMessage = createDummySOAPMessage(); 98 Properties properties = new Properties(); 99 properties.put("clientName.sender.sender:1234", "replacedSender"); 100 101 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 102 103 assertEquals("replacedSender", fixture.getClientName()); 104 } 105 106 /** 107 * 108 */ 109 @Test 110 public void test_ClientName_05() throws Exception { 111 HttpExchange exchange = createDummyExchange(); 112 SOAPMessage dummyMessage = createDummySOAPMessage(); 113 Properties properties = new Properties(); 114 properties.put("clientName.receiver.receiver", "replacedSender"); 115 116 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 117 118 assertEquals("replacedSender", fixture.getClientName()); 119 } 120 121 /** 122 * 123 */ 124 @Test 125 public void test_ClientName_06() throws Exception { 126 HttpExchange exchange = createDummyExchange(); 127 SOAPMessage dummyMessage = createDummySOAPMessage(); 128 Properties properties = new Properties(); 129 properties.put("clientName.receiver.receiver:5678", "replacedSender"); 130 131 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 132 133 assertEquals("replacedSender", fixture.getClientName()); 134 } 135 136 /** 137 * 138 */ 139 @Test 140 public void test_ClientName_07() throws Exception { 141 HttpExchange exchange = createDummyExchange(); 142 SOAPMessage dummyMessage = createDummySOAPMessage(); 143 Properties properties = new Properties(); 144 properties.put("clientName.sender.othersender", "replacedSender"); 145 146 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 147 148 assertEquals("sender:1234", fixture.getClientName()); 149 } 150 151 /** 152 * 153 */ 154 @Test 155 public void test_ClientName_08() throws Exception { 156 HttpExchange exchange = createDummyExchange(); 157 SOAPMessage dummyMessage = createDummySOAPMessage(); 158 Properties properties = new Properties(); 159 properties.put("clientName.sender.othersender:1234", "replacedSender"); 160 161 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 162 163 assertEquals("sender:1234", fixture.getClientName()); 164 } 165 166 /** 167 * 168 */ 169 @Test 170 public void test_ClientName_09() throws Exception { 171 HttpExchange exchange = createDummyExchange(); 172 SOAPMessage dummyMessage = createDummySOAPMessage(); 173 Properties properties = new Properties(); 174 properties.put("clientName.receiver.otherreceiver", "replacedSender"); 175 176 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 177 178 assertEquals("sender:1234", fixture.getClientName()); 179 } 180 181 /** 182 * 183 */ 184 @Test 185 public void test_ClientName_10() throws Exception { 186 HttpExchange exchange = createDummyExchange(); 187 SOAPMessage dummyMessage = createDummySOAPMessage(); 188 Properties properties = new Properties(); 189 properties.put("clientName.receiver.otherreceiver:5678", "replacedSender"); 190 191 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 192 193 assertEquals("sender:1234", fixture.getClientName()); 194 } 195 196 /** 197 * 198 */ 199 @Test 200 public void test_ServiceName_01() throws Exception { 201 HttpExchange exchange = createDummyExchange(); 202 SOAPMessage dummyMessage = createDummySOAPMessage(); 203 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, null); 204 205 assertEquals("/service/path", fixture.getServiceName()); 206 } 207 208 /** 209 * 210 */ 211 @Test 212 public void test_ServiceName_02() throws Exception { 213 HttpExchange exchange = createDummyExchange(); 214 SOAPMessage dummyMessage = createDummySOAPMessage(); 215 Properties properties = new Properties(); 216 217 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 218 219 assertEquals("/service/path", fixture.getServiceName()); 220 } 221 222 /** 223 * 224 */ 225 @Test 226 public void test_ServiceName_03() throws Exception { 227 HttpExchange exchange = createDummyExchange(); 228 SOAPMessage dummyMessage = createDummySOAPMessage(); 229 Properties properties = new Properties(); 230 properties.put("serviceName.path./service/path", "replacedService"); 231 232 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 233 234 assertEquals("replacedService", fixture.getServiceName()); 235 } 236 237 /** 238 * 239 */ 240 @Test 241 public void test_ServiceName_04() throws Exception { 242 HttpExchange exchange = createDummyExchange(); 243 SOAPMessage dummyMessage = createDummySOAPMessage(); 244 Properties properties = new Properties(); 245 properties.put("serviceName.path./service/otherpath", "replacedService"); 246 247 SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); 248 249 assertEquals("/service/path", fixture.getServiceName()); 250 } 251 252 /** 253 * 254 */ 255 private HttpExchange createDummyExchange() { 256 HttpExchange result = new HttpExchange(); 257 result.setSender(createDummyAddress("sender", "1.2.3.4", 1234)); 258 result.setReceiver(createDummyAddress("receiver", "5.6.7.8", 5678)); 259 result.setRequest(createDummyRequest()); 260 return result; 261 } 262 263 /** 264 * 265 */ 266 private Address createDummyAddress(String host, String ip, int port) { 267 Address address = new Address(); 268 address.setHost(host); 269 address.setIp(ip); 270 address.setPort(BigInteger.valueOf(port)); 271 return address; 272 } 273 274 /** 275 * 276 */ 277 private HttpRequest createDummyRequest() { 278 HttpRequest request = new HttpRequest(); 279 request.setUrl("http://receiver:5678/service/path"); 280 return request; 281 } 282 283 /** 284 * 285 */ 286 private SOAPMessage createDummySOAPMessage() throws Exception { 287 MessageFactory factory = MessageFactory.newInstance(); 288 SOAPMessage message = factory.createMessage(); 289 return message; 290 } 291 292 39 293 } -
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SOAPEventType.java
r1884 r1906 65 65 /** 66 66 * <p> 67 * the name of the service; this is either the path or, if a path map is available 67 * the name of the client; this is either the host/ip and port of the sender or, if a path 68 * map is available, a human readable name that may be based also on the receiver 69 * </p> 70 */ 71 private final String clientName; 72 73 /** 74 * <p> 75 * the name of the service; this is either the path or, if a path map is available, a human 76 * readable name that is mapped to the path 68 77 * </p> 69 78 */ … … 107 116 StringBuffer nameBuffer = new StringBuffer("SOAPEvent"); 108 117 109 boolean somethingAdded = false; 110 118 // determine the client name 119 if (urlNameMap == null) { 120 clientName = exchange.getSender().getHost() + ":" + exchange.getSender().getPort(); 121 } 122 else { 123 // check for a mapping of the sender host 124 String key = "clientName.sender." + exchange.getSender().getHost(); 125 String value = urlNameMap.getProperty(key); 126 127 if (value == null) { 128 key += ":" + exchange.getSender().getPort(); 129 value = urlNameMap.getProperty(key); 130 } 131 132 if (value == null) { 133 key = "clientName.receiver." + exchange.getReceiver().getHost(); 134 value = urlNameMap.getProperty(key); 135 } 136 137 if (value == null) { 138 key += ":" + exchange.getReceiver().getPort(); 139 value = urlNameMap.getProperty(key); 140 } 141 142 if (value != null) { 143 clientName = value; 144 } 145 else { 146 clientName = exchange.getSender().getHost() + ":" + exchange.getSender().getPort(); 147 } 148 } 149 150 nameBuffer.append(clientName); 151 152 // determine the service name 111 153 if (path != null) { 112 nameBuffer.append(" (");113 if ( urlNameMap==null) {154 nameBuffer.append(", "); 155 if (urlNameMap == null) { 114 156 serviceName = path; 115 } else { 116 String value = urlNameMap.getProperty(path); 117 if( value!=null ) { 157 } 158 else { 159 String value = urlNameMap.getProperty("serviceName.path." + path); 160 if (value != null) { 118 161 serviceName = value; 119 } else { 162 } 163 else { 120 164 serviceName = path; 121 165 } 122 166 } 123 167 nameBuffer.append(serviceName); 124 somethingAdded = true;125 }else {168 } 169 else { 126 170 serviceName = "NA"; 127 171 } 128 172 129 173 if (calledMethod != null) { 130 nameBuffer.append( somethingAdded ? ", " : "(");174 nameBuffer.append(", "); 131 175 nameBuffer.append(calledMethod); 132 somethingAdded = true;133 176 } 134 177 … … 137 180 138 181 if ((senderStr != null) && (receiverStr != null)) { 139 nameBuffer.append( somethingAdded ? ", " : "(");182 nameBuffer.append(", "); 140 183 nameBuffer.append(senderStr); 141 184 nameBuffer.append(" --> "); 142 185 nameBuffer.append(receiverStr); 143 somethingAdded = true;144 186 } 145 187 else if (senderStr != null) { 146 nameBuffer.append( somethingAdded ? ", " : "(");188 nameBuffer.append(", "); 147 189 nameBuffer.append(senderStr); 148 somethingAdded = true;149 190 } 150 191 else if (receiverStr != null) { 151 nameBuffer.append( somethingAdded ? ", " : "(");192 nameBuffer.append(", "); 152 193 nameBuffer.append(receiverStr); 153 somethingAdded = true; 154 } 155 156 if (somethingAdded) { 157 nameBuffer.append(")"); 158 } 194 } 195 196 nameBuffer.append(")"); 159 197 160 198 this.name = nameBuffer.toString(); … … 170 208 public String getCalledMethod() { 171 209 return calledMethod; 210 } 211 212 /** 213 * <p> 214 * the name of the client calling in this request 215 * </p> 216 * 217 * @return the name of the client calling in this request 218 */ 219 public String getClientName() { 220 return clientName; 172 221 } 173 222 … … 229 278 super.equals(obj) && 230 279 HTTPUtils.equals(calledMethod, ((SOAPEventType) obj).calledMethod) && 231 HTTPUtils.equals(serviceName, ((SOAPEventType) obj).serviceName); 280 HTTPUtils.equals(serviceName, ((SOAPEventType) obj).serviceName) && 281 HTTPUtils.equals(clientName, ((SOAPEventType) obj).clientName); 232 282 } 233 283 else { … … 247 297 if( serviceName != null ) { 248 298 hashCode += serviceName.hashCode(); 299 } 300 if( clientName != null ) { 301 hashCode += clientName.hashCode(); 249 302 } 250 303 return hashCode;
Note: See TracChangeset
for help on using the changeset viewer.