|
44 | 44 | import org.apache.synapse.rest.RESTRequestHandler; |
45 | 45 | import org.apache.synapse.task.SynapseTaskManager; |
46 | 46 | import org.apache.synapse.transport.passthru.util.RelayUtils; |
| 47 | +import org.apache.synapse.unittest.UnitTestingExecutor; |
47 | 48 | import org.apache.synapse.util.concurrent.SynapseThreadPool; |
48 | 49 | import org.apache.synapse.util.xpath.ext.SynapseXpathFunctionContextProvider; |
49 | 50 | import org.apache.synapse.util.xpath.ext.SynapseXpathVariableResolver; |
@@ -81,6 +82,9 @@ public class Axis2SynapseEnvironment implements SynapseEnvironment { |
81 | 82 | Map<QName, SynapseXpathVariableResolver> xpathVariableExtensions = |
82 | 83 | new HashMap<QName, SynapseXpathVariableResolver>(); |
83 | 84 |
|
| 85 | + /** Unit test mode is enabled/disabled*/ |
| 86 | + private boolean isUnitTestEnabled = false; |
| 87 | + |
84 | 88 | public Axis2SynapseEnvironment(SynapseConfiguration synCfg) { |
85 | 89 |
|
86 | 90 | int coreThreads = SynapseThreadPool.SYNAPSE_CORE_THREADS; |
@@ -124,7 +128,25 @@ public Axis2SynapseEnvironment(ConfigurationContext cfgCtx, |
124 | 128 | public Axis2SynapseEnvironment(ConfigurationContext cfgCtx, |
125 | 129 | SynapseConfiguration synapseConfig, ServerContextInformation contextInformation) { |
126 | 130 | this(cfgCtx, synapseConfig); |
127 | | - this.contextInformation = contextInformation; |
| 131 | + this.contextInformation = contextInformation; |
| 132 | + setSeverUnitTestMode(contextInformation); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * This method is to set the unit test mode is enabled. |
| 137 | + * unit test message context and environment initializes |
| 138 | + */ |
| 139 | + private void setSeverUnitTestMode(ServerContextInformation contextInformation) { |
| 140 | + if (Boolean.parseBoolean(System.getProperty("synapseTest"))) { |
| 141 | + setUnitTestEnabled(true); |
| 142 | + contextInformation.setServerUnitTestModeEnabled(true); |
| 143 | + log.info("Synapse unit testing server enabled"); |
| 144 | + |
| 145 | + //starting UnitTestingExecutor |
| 146 | + UnitTestingExecutor testExecutor = UnitTestingExecutor.getExecuteInstance(); |
| 147 | + testExecutor.setSynapseConfiguration(this.synapseConfig); |
| 148 | + testExecutor.start(); |
| 149 | + } |
128 | 150 | } |
129 | 151 |
|
130 | 152 | public boolean injectMessage(final MessageContext synCtx) { |
@@ -545,4 +567,22 @@ private Mediator getProxyOutSequence(MessageContext synCtx, ProxyService proxySe |
545 | 567 | } |
546 | 568 | return null; |
547 | 569 | } |
| 570 | + |
| 571 | + /** |
| 572 | + * Whether unit test is enabled in the environment. |
| 573 | + * |
| 574 | + * @return whether debugging is enabled in the environment |
| 575 | + */ |
| 576 | + public boolean isUnitTestEnabled() { |
| 577 | + return isUnitTestEnabled; |
| 578 | + } |
| 579 | + |
| 580 | + /** |
| 581 | + * set unit test mode enabled in the environment. |
| 582 | + * |
| 583 | + * @param isUnitTestEnabled boolean value of unit test mode |
| 584 | + */ |
| 585 | + public void setUnitTestEnabled(boolean isUnitTestEnabled) { |
| 586 | + this.isUnitTestEnabled = isUnitTestEnabled; |
| 587 | + } |
548 | 588 | } |
0 commit comments