[1599] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
| 15 | package de.ugoe.cs.autoquest.http.eventcore; |
---|
| 16 | |
---|
[1906] | 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 | |
---|
[1599] | 25 | import nl.jqno.equalsverifier.EqualsVerifier; |
---|
| 26 | import nl.jqno.equalsverifier.Warning; |
---|
| 27 | |
---|
| 28 | import org.junit.Test; |
---|
| 29 | |
---|
| 30 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType; |
---|
[1906] | 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; |
---|
[1599] | 34 | |
---|
| 35 | /** |
---|
[1906] | 36 | * |
---|
[1599] | 37 | * @author Patrick Harms |
---|
| 38 | */ |
---|
[1906] | 39 | public class SOAPEventTypeTest { |
---|
[1599] | 40 | |
---|
[1906] | 41 | /** |
---|
| 42 | * |
---|
| 43 | */ |
---|
[1599] | 44 | @Test |
---|
| 45 | public void test_EqualsContract_01() { |
---|
| 46 | EqualsVerifier.forClass(SOAPEventType.class) |
---|
| 47 | .suppress(Warning.NONFINAL_FIELDS).withRedefinedSuperclass().verify(); |
---|
| 48 | } |
---|
| 49 | |
---|
[1906] | 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(); |
---|
[1910] | 114 | properties.put("clientName.receiver.server.receiver", "replacedSender"); |
---|
[1906] | 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(); |
---|
[1910] | 129 | properties.put("clientName.receiver.server.receiver:5678", "replacedSender"); |
---|
[1906] | 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(); |
---|
[1910] | 144 | properties.put("clientName.receiver.port.5678", "replacedSender"); |
---|
[1906] | 145 | |
---|
| 146 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 147 | |
---|
[1910] | 148 | assertEquals("replacedSender", fixture.getClientName()); |
---|
[1906] | 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(); |
---|
[1910] | 159 | properties.put("clientName.sender.othersender", "replacedSender"); |
---|
[1906] | 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(); |
---|
[1910] | 174 | properties.put("clientName.sender.othersender:1234", "replacedSender"); |
---|
[1906] | 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(); |
---|
[1910] | 189 | properties.put("clientName.receiver.server.otherreceiver", "replacedSender"); |
---|
[1906] | 190 | |
---|
| 191 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 192 | |
---|
| 193 | assertEquals("sender:1234", fixture.getClientName()); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | /** |
---|
| 197 | * |
---|
| 198 | */ |
---|
| 199 | @Test |
---|
[1910] | 200 | public void test_ClientName_11() throws Exception { |
---|
| 201 | HttpExchange exchange = createDummyExchange(); |
---|
| 202 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 203 | Properties properties = new Properties(); |
---|
| 204 | properties.put("clientName.receiver.server.otherreceiver:5678", "replacedSender"); |
---|
| 205 | |
---|
| 206 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 207 | |
---|
| 208 | assertEquals("sender:1234", fixture.getClientName()); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | /** |
---|
| 212 | * |
---|
| 213 | */ |
---|
| 214 | @Test |
---|
| 215 | public void test_ClientName_12() throws Exception { |
---|
| 216 | HttpExchange exchange = createDummyExchange(); |
---|
| 217 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 218 | Properties properties = new Properties(); |
---|
| 219 | properties.put("clientName.receiver.port.5679", "replacedSender"); |
---|
| 220 | |
---|
| 221 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 222 | |
---|
| 223 | assertEquals("sender:1234", fixture.getClientName()); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | * |
---|
| 228 | */ |
---|
| 229 | @Test |
---|
[1912] | 230 | public void test_ClientName_13() throws Exception { |
---|
| 231 | HttpExchange exchange = createDummyExchange(); |
---|
| 232 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 233 | Properties properties = new Properties(); |
---|
| 234 | properties.put("clientName.default", "defaultName"); |
---|
| 235 | |
---|
| 236 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 237 | |
---|
| 238 | assertEquals("defaultName", fixture.getClientName()); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /** |
---|
| 242 | * |
---|
| 243 | */ |
---|
| 244 | @Test |
---|
| 245 | public void test_ClientName_14() throws Exception { |
---|
| 246 | HttpExchange exchange = createDummyExchange(); |
---|
| 247 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 248 | Properties properties = new Properties(); |
---|
| 249 | properties.put("clientName.default", "defaultName"); |
---|
| 250 | properties.put("clientName.receiver.server.receiver:5678", "replacedSender"); |
---|
| 251 | |
---|
| 252 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 253 | |
---|
| 254 | assertEquals("replacedSender", fixture.getClientName()); |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | /** |
---|
| 258 | * |
---|
| 259 | */ |
---|
| 260 | @Test |
---|
[1906] | 261 | public void test_ServiceName_01() throws Exception { |
---|
| 262 | HttpExchange exchange = createDummyExchange(); |
---|
| 263 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 264 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, null); |
---|
| 265 | |
---|
| 266 | assertEquals("/service/path", fixture.getServiceName()); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /** |
---|
| 270 | * |
---|
| 271 | */ |
---|
| 272 | @Test |
---|
| 273 | public void test_ServiceName_02() throws Exception { |
---|
| 274 | HttpExchange exchange = createDummyExchange(); |
---|
| 275 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 276 | Properties properties = new Properties(); |
---|
| 277 | |
---|
| 278 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 279 | |
---|
| 280 | assertEquals("/service/path", fixture.getServiceName()); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /** |
---|
| 284 | * |
---|
| 285 | */ |
---|
| 286 | @Test |
---|
| 287 | public void test_ServiceName_03() throws Exception { |
---|
| 288 | HttpExchange exchange = createDummyExchange(); |
---|
| 289 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 290 | Properties properties = new Properties(); |
---|
| 291 | properties.put("serviceName.path./service/path", "replacedService"); |
---|
| 292 | |
---|
| 293 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 294 | |
---|
| 295 | assertEquals("replacedService", fixture.getServiceName()); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | /** |
---|
| 299 | * |
---|
| 300 | */ |
---|
| 301 | @Test |
---|
| 302 | public void test_ServiceName_04() throws Exception { |
---|
| 303 | HttpExchange exchange = createDummyExchange(); |
---|
| 304 | SOAPMessage dummyMessage = createDummySOAPMessage(); |
---|
| 305 | Properties properties = new Properties(); |
---|
| 306 | properties.put("serviceName.path./service/otherpath", "replacedService"); |
---|
| 307 | |
---|
| 308 | SOAPEventType fixture = new SOAPEventType(exchange, dummyMessage, null, properties); |
---|
| 309 | |
---|
| 310 | assertEquals("/service/path", fixture.getServiceName()); |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /** |
---|
| 314 | * |
---|
| 315 | */ |
---|
| 316 | private HttpExchange createDummyExchange() { |
---|
| 317 | HttpExchange result = new HttpExchange(); |
---|
| 318 | result.setSender(createDummyAddress("sender", "1.2.3.4", 1234)); |
---|
| 319 | result.setReceiver(createDummyAddress("receiver", "5.6.7.8", 5678)); |
---|
| 320 | result.setRequest(createDummyRequest()); |
---|
| 321 | return result; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | /** |
---|
| 325 | * |
---|
| 326 | */ |
---|
| 327 | private Address createDummyAddress(String host, String ip, int port) { |
---|
| 328 | Address address = new Address(); |
---|
| 329 | address.setHost(host); |
---|
| 330 | address.setIp(ip); |
---|
| 331 | address.setPort(BigInteger.valueOf(port)); |
---|
| 332 | return address; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | /** |
---|
| 336 | * |
---|
| 337 | */ |
---|
| 338 | private HttpRequest createDummyRequest() { |
---|
| 339 | HttpRequest request = new HttpRequest(); |
---|
| 340 | request.setUrl("http://receiver:5678/service/path"); |
---|
| 341 | return request; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | /** |
---|
| 345 | * |
---|
| 346 | */ |
---|
| 347 | private SOAPMessage createDummySOAPMessage() throws Exception { |
---|
| 348 | MessageFactory factory = MessageFactory.newInstance(); |
---|
| 349 | SOAPMessage message = factory.createMessage(); |
---|
| 350 | return message; |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | |
---|
[1599] | 354 | } |
---|