[1986] | 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. |
---|
| 59 | getDeclaredField("soapRequestBodies"); |
---|
| 60 | |
---|
| 61 | privateStringField.setAccessible(true); |
---|
| 62 | |
---|
| 63 | Map<SimpleSOAPEventType, ListOrderedSet<String>> internalMapExpected = (Map<SimpleSOAPEventType, ListOrderedSet<String>>) privateStringField.get(EqualSOAPDataMap.getInstance()); |
---|
| 64 | |
---|
| 65 | // serialize |
---|
| 66 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
---|
| 67 | ObjectOutputStream oos = new ObjectOutputStream(out); |
---|
| 68 | oos.writeObject(EqualSOAPDataMap.getInstance()); |
---|
| 69 | oos.close(); |
---|
| 70 | |
---|
| 71 | EqualSOAPDataMap.getInstance().reset(); |
---|
| 72 | |
---|
| 73 | // deserialize |
---|
| 74 | byte[] pickled = out.toByteArray(); |
---|
| 75 | InputStream in = new ByteArrayInputStream(pickled); |
---|
| 76 | ObjectInputStream ois = new ObjectInputStream(in); |
---|
| 77 | ois.readObject(); |
---|
| 78 | ois.close(); |
---|
| 79 | |
---|
| 80 | Map<SimpleSOAPEventType, ListOrderedSet<String>> internalMapResult = (Map<SimpleSOAPEventType, ListOrderedSet<String>>) privateStringField.get(EqualSOAPDataMap.getInstance()); |
---|
| 81 | |
---|
| 82 | assertNotSame(internalMapExpected, internalMapResult); |
---|
| 83 | assertEquals(internalMapExpected, internalMapResult); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|