1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.loadtest.assertions;
14
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.apache.log4j.Logger;
21
22 import com.eviware.soapui.SoapUI;
23 import com.eviware.soapui.config.LoadTestAssertionConfig;
24 import com.eviware.soapui.impl.wsdl.loadtest.LoadTestAssertion;
25 import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
26
27 /***
28 * Registry for available LoadTestAssertions
29 *
30 * @author Ole.Matzura
31 */
32
33 public class LoadTestAssertionRegistry
34 {
35 private static LoadTestAssertionRegistry instance;
36 private Map<String,Class<? extends AbstractLoadTestAssertion> > availableAssertions = new HashMap<String,Class<? extends AbstractLoadTestAssertion> >();
37 private final static Logger logger = Logger.getLogger( LoadTestAssertionRegistry.class );
38
39 public LoadTestAssertionRegistry()
40 {
41 availableAssertions.put( TestStepAverageAssertion.STEP_AVERAGE_TYPE, TestStepAverageAssertion.class );
42 availableAssertions.put( TestStepTpsAssertion.STEP_TPS_TYPE, TestStepTpsAssertion.class );
43 availableAssertions.put( TestStepMaxAssertion.STEP_MAXIMUM_TYPE, TestStepMaxAssertion.class );
44 availableAssertions.put( TestStepStatusAssertion.STEP_STATUS_TYPE, TestStepStatusAssertion.class );
45 availableAssertions.put( MaxErrorsAssertion.MAX_ERRORS_TYPE, MaxErrorsAssertion.class );
46 }
47
48 public static synchronized LoadTestAssertionRegistry getInstance()
49 {
50 if( instance == null )
51 instance = new LoadTestAssertionRegistry();
52
53 return instance;
54 }
55
56 public static AbstractLoadTestAssertion buildAssertion(LoadTestAssertionConfig config, WsdlLoadTest loadTest)
57 {
58 try
59 {
60 Class<? extends AbstractLoadTestAssertion> clazz = getInstance().availableAssertions.get(config.getType());
61 Constructor<? extends AbstractLoadTestAssertion> ctor = clazz
62 .getConstructor(new Class[] { LoadTestAssertionConfig.class, WsdlLoadTest.class });
63
64 return (AbstractLoadTestAssertion) ctor.newInstance(config, loadTest );
65 }
66 catch (SecurityException e)
67 {
68 SoapUI.logError( e );
69 }
70 catch (NoSuchMethodException e)
71 {
72 SoapUI.logError( e );
73 }
74 catch (IllegalArgumentException e)
75 {
76 SoapUI.logError( e );
77 }
78 catch (InstantiationException e)
79 {
80 SoapUI.logError( e );
81 }
82 catch (IllegalAccessException e)
83 {
84 SoapUI.logError( e );
85 }
86 catch (InvocationTargetException e)
87 {
88 SoapUI.logError( e );
89 }
90
91 return null;
92 }
93
94 public static LoadTestAssertionConfig createAssertionConfig( String type )
95 {
96 LoadTestAssertionConfig config = LoadTestAssertionConfig.Factory.newInstance();
97 config.setType( type );
98 return config;
99 }
100
101 public static String[] getAvailableAssertions()
102 {
103 return getInstance().availableAssertions.keySet().toArray(
104 new String[getInstance().availableAssertions.size()] );
105 }
106
107 public static LoadTestAssertion createAssertion(String type, WsdlLoadTest loadTest )
108 {
109 LoadTestAssertionConfig config = createAssertionConfig( type );
110 return buildAssertion( config, loadTest );
111 }
112 }