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 | |
---|
17 | import static org.junit.Assert.*; |
---|
18 | |
---|
19 | import java.io.ByteArrayInputStream; |
---|
20 | import java.io.ByteArrayOutputStream; |
---|
21 | import java.io.File; |
---|
22 | import java.io.InputStream; |
---|
23 | import java.io.ObjectInputStream; |
---|
24 | import java.io.ObjectOutputStream; |
---|
25 | import java.lang.reflect.Field; |
---|
26 | import java.util.List; |
---|
27 | import java.util.Map; |
---|
28 | |
---|
29 | import org.apache.commons.collections4.set.ListOrderedSet; |
---|
30 | import org.junit.Test; |
---|
31 | |
---|
32 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
33 | import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; |
---|
34 | import de.ugoe.cs.autoquest.plugin.http.SOAPUtils; |
---|
35 | import de.ugoe.cs.autoquest.plugin.http.eventcore.EqualSOAPDataMap; |
---|
36 | import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType; |
---|
37 | |
---|
38 | /** |
---|
39 | * @author Steffen Herbold |
---|
40 | */ |
---|
41 | public class EqualSOAPDataMapTest { |
---|
42 | |
---|
43 | /** |
---|
44 | * |
---|
45 | */ |
---|
46 | @SuppressWarnings("unchecked") |
---|
47 | @Test |
---|
48 | public void testSerialization_1() throws Exception { |
---|
49 | HTTPLogParser parser = |
---|
50 | new HTTPLogParser(new File(ClassLoader |
---|
51 | .getSystemResource("testParseFile_3_properties.txt").getFile())); |
---|
52 | parser.parseFile(new File(ClassLoader.getSystemResource("testParseFile_3_logfile.log") |
---|
53 | .getFile())); |
---|
54 | for (List<Event> sequence : parser.getSequences()) { |
---|
55 | SOAPUtils.convertToSimpleSOAPEvent(sequence, true); |
---|
56 | } |
---|
57 | |
---|
58 | Field privateStringField = EqualSOAPDataMap.class.getDeclaredField("soapRequestBodies"); |
---|
59 | |
---|
60 | privateStringField.setAccessible(true); |
---|
61 | |
---|
62 | Map<SimpleSOAPEventType, ListOrderedSet<String>> internalMapExpected = |
---|
63 | (Map<SimpleSOAPEventType, ListOrderedSet<String>>) privateStringField |
---|
64 | .get(EqualSOAPDataMap.getInstance()); |
---|
65 | |
---|
66 | // serialize |
---|
67 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
---|
68 | ObjectOutputStream oos = new ObjectOutputStream(out); |
---|
69 | oos.writeObject(EqualSOAPDataMap.getInstance()); |
---|
70 | oos.close(); |
---|
71 | |
---|
72 | EqualSOAPDataMap.getInstance().reset(); |
---|
73 | |
---|
74 | // deserialize |
---|
75 | byte[] pickled = out.toByteArray(); |
---|
76 | InputStream in = new ByteArrayInputStream(pickled); |
---|
77 | ObjectInputStream ois = new ObjectInputStream(in); |
---|
78 | ois.readObject(); |
---|
79 | ois.close(); |
---|
80 | |
---|
81 | Map<SimpleSOAPEventType, ListOrderedSet<String>> internalMapResult = |
---|
82 | (Map<SimpleSOAPEventType, ListOrderedSet<String>>) privateStringField |
---|
83 | .get(EqualSOAPDataMap.getInstance()); |
---|
84 | |
---|
85 | assertNotSame(internalMapExpected, internalMapResult); |
---|
86 | assertEquals(internalMapExpected, internalMapResult); |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|