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

Last change on this file since 1986 was 1986, checked in by sherbold, 9 years ago
  • EqualSOAPDataMap now serializable
  • 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.
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}
Note: See TracBrowser for help on using the repository browser.