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 @SuppressWarnings( "unused" )
38 private final static Logger logger = Logger.getLogger( LoadTestAssertionRegistry.class );
39
40 public LoadTestAssertionRegistry()
41 {
42 availableAssertions.put( TestStepAverageAssertion.STEP_AVERAGE_TYPE, TestStepAverageAssertion.class );
43 availableAssertions.put( TestStepTpsAssertion.STEP_TPS_TYPE, TestStepTpsAssertion.class );
44 availableAssertions.put( TestStepMaxAssertion.STEP_MAXIMUM_TYPE, TestStepMaxAssertion.class );
45 availableAssertions.put( TestStepStatusAssertion.STEP_STATUS_TYPE, TestStepStatusAssertion.class );
46 availableAssertions.put( MaxErrorsAssertion.MAX_ERRORS_TYPE, MaxErrorsAssertion.class );
47 }
48
49 public static synchronized LoadTestAssertionRegistry getInstance()
50 {
51 if( instance == null )
52 instance = new LoadTestAssertionRegistry();
53
54 return instance;
55 }
56
57 public static AbstractLoadTestAssertion buildAssertion( LoadTestAssertionConfig config, WsdlLoadTest loadTest )
58 {
59 try
60 {
61 Class<? extends AbstractLoadTestAssertion> clazz = getInstance().availableAssertions.get( config.getType() );
62 Constructor<? extends AbstractLoadTestAssertion> ctor = clazz.getConstructor( new Class[] {
63 LoadTestAssertionConfig.class, WsdlLoadTest.class } );
64
65 return ( AbstractLoadTestAssertion )ctor.newInstance( config, loadTest );
66 }
67 catch( SecurityException e )
68 {
69 SoapUI.logError( e );
70 }
71 catch( NoSuchMethodException e )
72 {
73 SoapUI.logError( e );
74 }
75 catch( IllegalArgumentException e )
76 {
77 SoapUI.logError( e );
78 }
79 catch( InstantiationException e )
80 {
81 SoapUI.logError( e );
82 }
83 catch( IllegalAccessException e )
84 {
85 SoapUI.logError( e );
86 }
87 catch( InvocationTargetException e )
88 {
89 SoapUI.logError( e );
90 }
91
92 return null;
93 }
94
95 public static LoadTestAssertionConfig createAssertionConfig( String type )
96 {
97 LoadTestAssertionConfig config = LoadTestAssertionConfig.Factory.newInstance();
98 config.setType( type );
99 return config;
100 }
101
102 public static String[] getAvailableAssertions()
103 {
104 return getInstance().availableAssertions.keySet().toArray( 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 }