source: trunk/autoquest-plugin-http-test/src/test/java/de/ugoe/cs/autoquest/http/eventcore/EqualSOAPDataMapTest.java @ 1987

Last change on this file since 1987 was 1987, checked in by sherbold, 9 years ago
  • code formatting
  • Property svn:mime-type set to text/plain
File size: 3.1 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.eventcore;
16
17import static org.junit.Assert.*;
18
19import java.io.ByteArrayInputStream;
20import java.io.ByteArrayOutputStream;
21import java.io.File;
22import java.io.InputStream;
23import java.io.ObjectInputStream;
24import java.io.ObjectOutputStream;
25import java.lang.reflect.Field;
26import java.util.List;
27import java.util.Map;
28
29import org.apache.commons.collections4.set.ListOrderedSet;
30import org.junit.Test;
31
32import de.ugoe.cs.autoquest.eventcore.Event;
33import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser;
34import de.ugoe.cs.autoquest.plugin.http.SOAPUtils;
35import de.ugoe.cs.autoquest.plugin.http.eventcore.EqualSOAPDataMap;
36import de.ugoe.cs.autoquest.plugin.http.eventcore.SimpleSOAPEventType;
37
38/**
39 * @author Steffen Herbold
40 */
41public 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}
Note: See TracBrowser for help on using the repository browser.