[1635] | 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;
|
---|
| 16 |
|
---|
| 17 | import static org.junit.Assert.*;
|
---|
| 18 |
|
---|
| 19 | import java.io.File;
|
---|
| 20 | import java.util.Collection;
|
---|
| 21 | import java.util.Iterator;
|
---|
[2003] | 22 | import java.util.LinkedList;
|
---|
[1635] | 23 | import java.util.List;
|
---|
[2003] | 24 | import java.util.logging.Level;
|
---|
[1635] | 25 |
|
---|
[2003] | 26 | import org.junit.BeforeClass;
|
---|
[1635] | 27 | import org.junit.Test;
|
---|
| 28 |
|
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
[2003] | 30 | import de.ugoe.cs.autoquest.eventcore.EventUtils;
|
---|
[1635] | 31 | import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
|
---|
[1925] | 32 | import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
|
---|
[1635] | 33 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType;
|
---|
| 34 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType;
|
---|
[2003] | 35 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType;
|
---|
| 36 | import de.ugoe.cs.util.console.Console;
|
---|
| 37 | import de.ugoe.cs.util.console.TextConsole;
|
---|
[1635] | 38 |
|
---|
| 39 | /**
|
---|
| 40 | * <p>
|
---|
[1925] | 41 | * Tests for the SOAPUtils
|
---|
[1635] | 42 | * </p>
|
---|
| 43 | *
|
---|
| 44 | * @author Steffen Herbold
|
---|
| 45 | */
|
---|
[1925] | 46 | public class SOAPUtilsTest {
|
---|
[2003] | 47 |
|
---|
| 48 | @BeforeClass
|
---|
| 49 | public static void setupBeforeClass() {
|
---|
| 50 | new TextConsole(Level.FINEST);
|
---|
| 51 | }
|
---|
[1987] | 52 |
|
---|
[1635] | 53 | @Test
|
---|
| 54 | public void testConvertToSimpleSOAPEvent_1() throws Exception {
|
---|
| 55 | HTTPLogParser parser =
|
---|
[1987] | 56 | new HTTPLogParser(new File(ClassLoader
|
---|
| 57 | .getSystemResource("testParseFile_3_properties.txt").getFile()));
|
---|
| 58 | parser.parseFile(new File(ClassLoader.getSystemResource("testParseFile_3_logfile.log")
|
---|
| 59 | .getFile()));
|
---|
[1988] | 60 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
[1635] | 61 |
|
---|
[1988] | 62 | assertNotNull(sequences);
|
---|
| 63 | assertFalse(sequences.isEmpty());
|
---|
[1635] | 64 |
|
---|
[1988] | 65 | Collection<List<Event>> newSequences = SOAPUtils.convertToSimpleSOAPEvent(sequences, false);
|
---|
| 66 |
|
---|
| 67 | assertNotNull(newSequences);
|
---|
| 68 | assertEquals(sequences.size(), newSequences.size());
|
---|
[1987] | 69 |
|
---|
[1988] | 70 | // compare sequences
|
---|
| 71 | Iterator<List<Event>> oldIter = sequences.iterator();
|
---|
| 72 | Iterator<List<Event>> newIter = newSequences.iterator();
|
---|
| 73 |
|
---|
| 74 | while( oldIter.hasNext() ) {
|
---|
| 75 | Iterator<Event> oldSeqIter = oldIter.next().iterator();
|
---|
| 76 | Iterator<Event> newSeqIter = newIter.next().iterator();
|
---|
| 77 |
|
---|
| 78 | while (oldSeqIter.hasNext()) {
|
---|
| 79 | Event oldEvent = oldSeqIter.next();
|
---|
| 80 | Event newEvent = newSeqIter.next();
|
---|
| 81 |
|
---|
| 82 | if (oldEvent.getType() instanceof SOAPEventType) {
|
---|
| 83 | assertTrue(newEvent.getType() instanceof SimpleSOAPEventType);
|
---|
| 84 | SOAPEventType oldEventType = (SOAPEventType) oldEvent.getType();
|
---|
| 85 | SimpleSOAPEventType newEventType = (SimpleSOAPEventType) newEvent.getType();
|
---|
| 86 | assertEquals(oldEventType.getCalledMethod(), newEventType.getCalledMethod());
|
---|
| 87 | assertEquals(oldEventType.getServiceName(), newEventType.getServiceName());
|
---|
| 88 | assertEquals(oldEventType.getClientName(), newEventType.getClientName());
|
---|
| 89 | assertNull(newEvent.getTarget());
|
---|
| 90 | }
|
---|
| 91 | else {
|
---|
| 92 | assertSame(oldEvent, newEvent);
|
---|
| 93 | }
|
---|
[1635] | 94 | }
|
---|
[1987] | 95 | }
|
---|
[2003] | 96 | }
|
---|
| 97 |
|
---|
| 98 | @Test
|
---|
| 99 | public void testDropInvalidResponseRequestPairs_1() throws Exception {
|
---|
| 100 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 101 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 102 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 103 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 104 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 105 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 106 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 107 |
|
---|
| 108 | List<Event> expectedSequence = new LinkedList<>(sequence);
|
---|
| 109 |
|
---|
| 110 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 111 |
|
---|
| 112 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 113 | Console.traceln(Level.INFO, getCurrentMethodName());
|
---|
| 114 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 115 |
|
---|
| 116 | assertEquals(expectedSequence, validSequence);
|
---|
| 117 | assertEquals(originalSequence, sequence);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | @Test
|
---|
| 121 | public void testDropInvalidResponseRequestPairs_2() throws Exception {
|
---|
| 122 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 123 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 124 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 125 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 126 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 127 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 128 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 129 |
|
---|
| 130 | List<Event> expectedSequence = new LinkedList<Event>();
|
---|
| 131 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 132 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 133 |
|
---|
| 134 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 135 |
|
---|
| 136 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 137 | Console.traceln(Level.INFO, getCurrentMethodName());
|
---|
| 138 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 139 |
|
---|
| 140 | assertEquals(expectedSequence, validSequence);
|
---|
| 141 | assertEquals(originalSequence, sequence);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | @Test
|
---|
| 145 | public void testDropInvalidResponseRequestPairs_3() throws Exception {
|
---|
| 146 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 147 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 148 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 149 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 150 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 151 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 152 |
|
---|
| 153 | List<Event> expectedSequence = new LinkedList<Event>();
|
---|
| 154 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 155 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 156 |
|
---|
| 157 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 158 |
|
---|
| 159 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 160 | Console.traceln(Level.INFO, getCurrentMethodName());
|
---|
| 161 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 162 |
|
---|
| 163 | assertEquals(expectedSequence, validSequence);
|
---|
| 164 | assertEquals(originalSequence, sequence);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | @Test
|
---|
| 168 | public void testDropInvalidResponseRequestPairs_4() throws Exception {
|
---|
| 169 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 170 | sequence.add(Event.STARTEVENT);
|
---|
| 171 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 172 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 173 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 174 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 175 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 176 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 177 | sequence.add(Event.ENDEVENT);
|
---|
| 178 |
|
---|
| 179 | List<Event> expectedSequence = new LinkedList<>(sequence);
|
---|
| 180 |
|
---|
| 181 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 182 |
|
---|
| 183 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 184 | Console.traceln(Level.INFO, getCurrentMethodName());
|
---|
| 185 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 186 |
|
---|
| 187 | assertEquals(expectedSequence, validSequence);
|
---|
| 188 | assertEquals(originalSequence, sequence);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | @Test
|
---|
| 192 | public void testDropInvalidResponseRequestPairs_5() throws Exception {
|
---|
| 193 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 194 | sequence.add(Event.STARTEVENT);
|
---|
| 195 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 196 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 197 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 198 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 199 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 200 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 201 | sequence.add(Event.ENDEVENT);
|
---|
| 202 |
|
---|
| 203 | List<Event> expectedSequence = new LinkedList<Event>();
|
---|
| 204 | expectedSequence.add(Event.STARTEVENT);
|
---|
| 205 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 206 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 207 | expectedSequence.add(Event.ENDEVENT);
|
---|
| 208 |
|
---|
| 209 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 210 |
|
---|
| 211 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 212 | Console.traceln(Level.INFO, getCurrentMethodName() );
|
---|
| 213 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 214 |
|
---|
| 215 | assertEquals(expectedSequence, validSequence);
|
---|
| 216 | assertEquals(originalSequence, sequence);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | @Test
|
---|
| 220 | public void testDropInvalidResponseRequestPairs_6() throws Exception {
|
---|
| 221 | List<Event> sequence = new LinkedList<Event>();
|
---|
| 222 | sequence.add(Event.STARTEVENT);
|
---|
| 223 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 224 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 225 | sequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 226 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 227 | sequence.add(new Event(new SimpleSOAPEventType("op2", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 228 | sequence.add(Event.ENDEVENT);
|
---|
| 229 |
|
---|
| 230 | List<Event> expectedSequence = new LinkedList<Event>();
|
---|
| 231 | expectedSequence.add(Event.STARTEVENT);
|
---|
| 232 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.REQUEST)));
|
---|
| 233 | expectedSequence.add(new Event(new SimpleSOAPEventType("op1", "foo", "bar", null, null, CallType.RESPONSE)));
|
---|
| 234 | expectedSequence.add(Event.ENDEVENT);
|
---|
| 235 |
|
---|
| 236 | List<Event> originalSequence = new LinkedList<>(sequence);
|
---|
| 237 |
|
---|
| 238 | List<Event> validSequence = SOAPUtils.dropInvalidResponseRequestPairs(sequence);
|
---|
| 239 | Console.traceln(Level.INFO, getCurrentMethodName());
|
---|
| 240 | EventUtils.traceSequence(Level.INFO, validSequence);
|
---|
| 241 |
|
---|
| 242 | assertEquals(expectedSequence, validSequence);
|
---|
| 243 | assertEquals(originalSequence, sequence);
|
---|
| 244 | }
|
---|
[1987] | 245 |
|
---|
[2003] | 246 | private String getCurrentMethodName() {
|
---|
| 247 | StackTraceElement stackTraceElements[] = (new Throwable()).getStackTrace();
|
---|
| 248 | return stackTraceElements[1].toString();
|
---|
[1635] | 249 | }
|
---|
[2003] | 250 |
|
---|
[1635] | 251 | }
|
---|