source: trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/SOAPUtilsTest.java @ 2003

Last change on this file since 2003 was 2003, checked in by sherbold, 9 years ago
  • extended SOAP utils with function that removes all invalid request/response pairs from a sequence of SimpleSOAPEvents
  • Property svn:mime-type set to text/plain
File size: 12.7 KB
Line 
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
15package de.ugoe.cs.autoquest.http;
16
17import static org.junit.Assert.*;
18
19import java.io.File;
20import java.util.Collection;
21import java.util.Iterator;
22import java.util.LinkedList;
23import java.util.List;
24import java.util.logging.Level;
25
26import org.junit.BeforeClass;
27import org.junit.Test;
28
29import de.ugoe.cs.autoquest.eventcore.Event;
30import de.ugoe.cs.autoquest.eventcore.EventUtils;
31import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
32import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
33import de.ugoe.cs.autoquest.plugin.http.eventcore.SOAPEventType;
34import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType;
35import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType.CallType;
36import de.ugoe.cs.util.console.Console;
37import de.ugoe.cs.util.console.TextConsole;
38
39/**
40 * <p>
41 * Tests for the SOAPUtils
42 * </p>
43 *
44 * @author Steffen Herbold
45 */
46public class SOAPUtilsTest {
47   
48    @BeforeClass
49    public static void setupBeforeClass() {
50        new TextConsole(Level.FINEST);
51    }
52
53    @Test
54    public void testConvertToSimpleSOAPEvent_1() throws Exception {
55        HTTPLogParser parser =
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()));
60        Collection<List<Event>> sequences = parser.getSequences();
61
62        assertNotNull(sequences);
63        assertFalse(sequences.isEmpty());
64
65        Collection<List<Event>> newSequences = SOAPUtils.convertToSimpleSOAPEvent(sequences, false);
66       
67        assertNotNull(newSequences);
68        assertEquals(sequences.size(), newSequences.size());
69
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                }
94            }
95        }
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    }
245
246    private  String getCurrentMethodName() {
247         StackTraceElement stackTraceElements[] = (new Throwable()).getStackTrace();
248         return stackTraceElements[1].toString();
249    }
250   
251}
Note: See TracBrowser for help on using the repository browser.