[1985] | 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.plugin.http.eventcore;
|
---|
| 16 |
|
---|
[1986] | 17 | import java.io.Serializable;
|
---|
[1985] | 18 | import java.util.Collections;
|
---|
| 19 | import java.util.HashMap;
|
---|
| 20 | import java.util.Map;
|
---|
| 21 | import java.util.Random;
|
---|
| 22 | import java.util.Set;
|
---|
| 23 |
|
---|
| 24 | import 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 | */
|
---|
[1986] | 33 | public class EqualSOAPDataMap implements Serializable {
|
---|
[1985] | 34 |
|
---|
[1986] | 35 | /** */
|
---|
| 36 | private static final long serialVersionUID = 1L;
|
---|
[1985] | 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Map with all soapRequestBodies for all equal {@link SimpleSOAPEventType}s
|
---|
| 40 | */
|
---|
[1986] | 41 | private Map<SimpleSOAPEventType, ListOrderedSet<String>> soapRequestBodies = new HashMap<>();
|
---|
[1985] | 42 |
|
---|
| 43 | /**
|
---|
| 44 | * random number generator for picking a random request body
|
---|
| 45 | */
|
---|
[1988] | 46 | private final Random random = new Random();
|
---|
| 47 |
|
---|
[1986] | 48 | /**
|
---|
| 49 | * <p>
|
---|
[1988] | 50 | * Default constructor.
|
---|
[1986] | 51 | * </p>
|
---|
| 52 | */
|
---|
[1988] | 53 | public EqualSOAPDataMap() {
|
---|
| 54 |
|
---|
[1986] | 55 | }
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * <p>
|
---|
[1985] | 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 | }
|
---|
[1986] | 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 | }
|
---|
[1988] | 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 | }
|
---|
[1985] | 124 | } |
---|