001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.loadtest.assertions;
014:
015: import java.lang.reflect.Constructor;
016: import java.lang.reflect.InvocationTargetException;
017: import java.util.HashMap;
018: import java.util.Map;
019:
020: import org.apache.log4j.Logger;
021:
022: import com.eviware.soapui.SoapUI;
023: import com.eviware.soapui.config.LoadTestAssertionConfig;
024: import com.eviware.soapui.impl.wsdl.loadtest.LoadTestAssertion;
025: import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
026:
027: /**
028: * Registry for available LoadTestAssertions
029: *
030: * @author Ole.Matzura
031: */
032:
033: public class LoadTestAssertionRegistry {
034: private static LoadTestAssertionRegistry instance;
035: private Map<String, Class<? extends AbstractLoadTestAssertion>> availableAssertions = new HashMap<String, Class<? extends AbstractLoadTestAssertion>>();
036: private final static Logger logger = Logger
037: .getLogger(LoadTestAssertionRegistry.class);
038:
039: public LoadTestAssertionRegistry() {
040: availableAssertions.put(
041: TestStepAverageAssertion.STEP_AVERAGE_TYPE,
042: TestStepAverageAssertion.class);
043: availableAssertions.put(TestStepTpsAssertion.STEP_TPS_TYPE,
044: TestStepTpsAssertion.class);
045: availableAssertions.put(TestStepMaxAssertion.STEP_MAXIMUM_TYPE,
046: TestStepMaxAssertion.class);
047: availableAssertions.put(
048: TestStepStatusAssertion.STEP_STATUS_TYPE,
049: TestStepStatusAssertion.class);
050: availableAssertions.put(MaxErrorsAssertion.MAX_ERRORS_TYPE,
051: MaxErrorsAssertion.class);
052: }
053:
054: public static synchronized LoadTestAssertionRegistry getInstance() {
055: if (instance == null)
056: instance = new LoadTestAssertionRegistry();
057:
058: return instance;
059: }
060:
061: public static AbstractLoadTestAssertion buildAssertion(
062: LoadTestAssertionConfig config, WsdlLoadTest loadTest) {
063: try {
064: Class<? extends AbstractLoadTestAssertion> clazz = getInstance().availableAssertions
065: .get(config.getType());
066: Constructor<? extends AbstractLoadTestAssertion> ctor = clazz
067: .getConstructor(new Class[] {
068: LoadTestAssertionConfig.class,
069: WsdlLoadTest.class });
070:
071: return (AbstractLoadTestAssertion) ctor.newInstance(config,
072: loadTest);
073: } catch (SecurityException e) {
074: SoapUI.logError(e);
075: } catch (NoSuchMethodException e) {
076: SoapUI.logError(e);
077: } catch (IllegalArgumentException e) {
078: SoapUI.logError(e);
079: } catch (InstantiationException e) {
080: SoapUI.logError(e);
081: } catch (IllegalAccessException e) {
082: SoapUI.logError(e);
083: } catch (InvocationTargetException e) {
084: SoapUI.logError(e);
085: }
086:
087: return null;
088: }
089:
090: public static LoadTestAssertionConfig createAssertionConfig(
091: String type) {
092: LoadTestAssertionConfig config = LoadTestAssertionConfig.Factory
093: .newInstance();
094: config.setType(type);
095: return config;
096: }
097:
098: public static String[] getAvailableAssertions() {
099: return getInstance().availableAssertions.keySet().toArray(
100: new String[getInstance().availableAssertions.size()]);
101: }
102:
103: public static LoadTestAssertion createAssertion(String type,
104: WsdlLoadTest loadTest) {
105: LoadTestAssertionConfig config = createAssertionConfig(type);
106: return buildAssertion(config, loadTest);
107: }
108: }
|