[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(); |
---|
| 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 | |
---|
[1599] | 293 | } |
---|