Changeset 1985


Ignore:
Timestamp:
07/06/15 11:26:21 (9 years ago)
Author:
sherbold
Message:
  • extracted EqualSOAPDataMap to separate file
Location:
trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/eventcore/SimpleSOAPEventType.java

    r1984 r1985  
    1717import java.io.ByteArrayInputStream; 
    1818import java.io.IOException; 
    19 import java.util.Collections; 
    20 import java.util.HashMap; 
    21 import java.util.Map; 
    22 import java.util.Random; 
    23 import java.util.Set; 
    2419 
    2520import javax.xml.parsers.DocumentBuilderFactory; 
    2621import javax.xml.parsers.ParserConfigurationException; 
    2722 
    28 import org.apache.commons.collections4.set.ListOrderedSet; 
    2923import org.w3c.dom.Element; 
    3024import org.xml.sax.SAXException; 
     
    260254     * @author Steffen Herbold 
    261255     */ 
    262     public static enum RequestBodyMode {LOCALEVENT, RANDOM}; 
    263      
    264     /** 
    265      * <p> 
    266      * 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. 
    267      * </p> 
    268      *  
    269      * @author Steffen Herbold 
    270      */ 
    271     public static class EqualSOAPDataMap { 
    272          
    273         /** 
    274          * Singleton. Handle to only instance of this class 
    275          */ 
    276         public final static EqualSOAPDataMap INSTANCE = new EqualSOAPDataMap(); 
    277          
    278         /** 
    279          * Map with all soapRequestBodies for all equal {@link SimpleSOAPEventType}s 
    280          */ 
    281         private final Map<SimpleSOAPEventType, ListOrderedSet<String>> soapRequestBodies = new HashMap<>(); 
    282          
    283         /** 
    284          * random number generator for picking a random request body 
    285          */ 
    286         private final Random random = new Random(1); // TODO static seed for testing 
    287          
    288         private EqualSOAPDataMap() { 
    289             // private constructor to avoid initialization 
    290         } 
    291  
    292         /** 
    293          * <p> 
    294          * Adds a new body to the map. 
    295          * </p> 
    296          * 
    297          * @param simpleSOAPEventType 
    298          */ 
    299         public void add(SimpleSOAPEventType simpleSOAPEventType, String soapRequestBody) { 
    300             if( soapRequestBody!=null ) { 
    301                 ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType); 
    302                 if( requestBodySet==null ) { 
    303                     requestBodySet = new ListOrderedSet<>(); 
    304                     soapRequestBodies.put(simpleSOAPEventType, requestBodySet); 
    305                 } 
    306                 requestBodySet.add(soapRequestBody); 
    307             } 
    308         } 
    309          
    310         /** 
    311          * <p> 
    312          * Retrieves all bodies associated with the simpleSoapEventType; null if not found 
    313          * </p> 
    314          * 
    315          * @param simpleSoapEventType 
    316          * @return 
    317          */ 
    318         public Set<String> getAll(SimpleSOAPEventType simpleSoapEventType) { 
    319             return Collections.unmodifiableSet(soapRequestBodies.get(simpleSoapEventType)); 
    320         } 
    321          
    322         /** 
    323          * <p> 
    324          * Randomly draws one of the SOAP event type bodies associated with the event 
    325          * </p> 
    326          * 
    327          * @param simpleSOAPEventType 
    328          * @return 
    329          */ 
    330         public String getRandom(SimpleSOAPEventType simpleSOAPEventType) { 
    331             ListOrderedSet<String> requestBodySet = soapRequestBodies.get(simpleSOAPEventType); 
    332             if( requestBodySet==null || requestBodySet.isEmpty() ) { 
    333                 throw new RuntimeException("no request body known for SimpleSOAPEventType: " + simpleSOAPEventType); 
    334             } 
    335              
    336             return requestBodySet.get(random.nextInt(requestBodySet.size())); 
    337         } 
    338     } 
     256    public static enum RequestBodyMode {LOCALEVENT, RANDOM} 
    339257} 
Note: See TracChangeset for help on using the changeset viewer.