source: trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/EqualSOAPDataMap.java @ 2215

Last change on this file since 2215 was 1988, checked in by sherbold, 9 years ago
  • updated EqualSOAPDataMap: not a singleton anymore, now each event has a reference to the map. the map is created when the SOAPEvents are converted to SimpleSOAPEvents using the appropriate method from the SOAPUtils
  • the logic for deciding if random SOAP requests are selected or the one of the event itself was changed within the SimpleSOAPEvents. Now methods for both are offered and the caller has to decide which method to choose
  • the test case generation in the model utils now has a parameter to decide if random data or the data of the SimpleSOAPEvents is used
  • Property svn:mime-type set to text/plain
File size: 3.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.plugin.http.eventcore;
16
17import java.io.Serializable;
18import java.util.Collections;
19import java.util.HashMap;
20import java.util.Map;
21import java.util.Random;
22import java.util.Set;
23
24import org.apache.commons.collections4.set.ListOrderedSet;
25
26/**
27 * <p>
28 * Handles all request bodies of equal SOAP events. Can be used to view either all request bodies sent to an operation or to randomly draw one of the bodies.
29 * </p>
30 *
31 * @author Steffen Herbold
32 */
33public class EqualSOAPDataMap implements Serializable {
34   
35    /**  */
36    private static final long serialVersionUID = 1L;
37   
38    /**
39     * Map with all soapRequestBodies for all equal {@link SimpleSOAPEventType}s
40     */
41    private Map<SimpleSOAPEventType, ListOrderedSet<String>> soapRequestBodies = new HashMap<>();
42   
43    /**
44     * random number generator for picking a random request body
45     */
46    private final Random random = new Random();
47
48    /**
49     * <p>
50     * Default constructor.
51     * </p>
52     */
53    public EqualSOAPDataMap() {
54       
55    }
56   
57    /**
58     * <p>
59     * Adds a new body to the map.
60     * </p>
61     *
62     * @param simpleSOAPEventType
63     */
64    public void add(SimpleSOAPEventType simpleSOAPEventType, String soapRequestBody) {
65        if( soapRequestBody!=null ) {
66            ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType);
67            if( requestBodySet==null ) {
68                requestBodySet = new ListOrderedSet<>();
69                soapRequestBodies.put(simpleSOAPEventType, requestBodySet);
70            }
71            requestBodySet.add(soapRequestBody);
72        }
73    }
74   
75    /**
76     * <p>
77     * Retrieves all bodies associated with the simpleSoapEventType; null if not found
78     * </p>
79     *
80     * @param simpleSoapEventType
81     * @return
82     */
83    public Set<String> getAll(SimpleSOAPEventType simpleSoapEventType) {
84        return Collections.unmodifiableSet(soapRequestBodies.get(simpleSoapEventType));
85    }
86   
87    /**
88     * <p>
89     * Randomly draws one of the SOAP event type bodies associated with the event
90     * </p>
91     *
92     * @param simpleSOAPEventType
93     * @return
94     */
95    public String getRandom(SimpleSOAPEventType simpleSOAPEventType) {
96        ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType);
97        if( requestBodySet==null || requestBodySet.isEmpty() ) {
98            throw new RuntimeException("no request body known for SimpleSOAPEventType: " + simpleSOAPEventType);
99        }
100       
101        return requestBodySet.get(random.nextInt(requestBodySet.size()));
102    }
103   
104    /**
105     * <p>
106     * resets the internal map by creating new one
107     * </p>
108     *
109     */
110    public void reset() {
111        soapRequestBodies = new HashMap<>();
112    }
113   
114    /**
115     * <p>
116     * returns is the current data map is empty
117     * </p>
118     *
119     * @return true if empty; false otherwise
120     */
121    public boolean isEmpty() {
122        return soapRequestBodies.isEmpty();
123    }
124}
Note: See TracBrowser for help on using the repository browser.