|
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; |
@@ -83,6 +84,9 @@ public class Axis2SynapseEnvironment implements SynapseEnvironment { |
83 | 84 |
|
84 | 85 | private boolean synapseDebugMode; |
85 | 86 |
|
| 87 | + /** Unit test mode is enabled/disabled*/ |
| 88 | + private boolean isUnitTestEnabled = false; |
| 89 | + |
86 | 90 | public Axis2SynapseEnvironment(SynapseConfiguration synCfg) { |
87 | 91 |
|
88 | 92 | int coreThreads = SynapseThreadPool.SYNAPSE_CORE_THREADS; |
@@ -126,7 +130,25 @@ public Axis2SynapseEnvironment(ConfigurationContext cfgCtx, |
126 | 130 | public Axis2SynapseEnvironment(ConfigurationContext cfgCtx, |
127 | 131 | SynapseConfiguration synapseConfig, ServerContextInformation contextInformation) { |
128 | 132 | this(cfgCtx, synapseConfig); |
129 | | - this.contextInformation = contextInformation; |
| 133 | + this.contextInformation = contextInformation; |
| 134 | + setSeverUnitTestMode(contextInformation); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * This method is to set the unit test mode is enabled. |
| 139 | + * unit test message context and environment initializes |
| 140 | + */ |
| 141 | + private void setSeverUnitTestMode(ServerContextInformation contextInformation) { |
| 142 | + if (Boolean.parseBoolean(System.getProperty("synapseTest"))) { |
| 143 | + setUnitTestEnabled(true); |
| 144 | + contextInformation.setServerUnitTestModeEnabled(true); |
| 145 | + log.info("Synapse unit testing server enabled"); |
| 146 | + |
| 147 | + //starting UnitTestingExecutor |
| 148 | + UnitTestingExecutor testExecutor = UnitTestingExecutor.getExecuteInstance(); |
| 149 | + testExecutor.setSynapseConfiguration(this.synapseConfig); |
| 150 | + testExecutor.start(); |
| 151 | + } |
130 | 152 | } |
131 | 153 |
|
132 | 154 | public boolean injectMessage(final MessageContext synCtx) { |
@@ -551,7 +573,26 @@ private Mediator getProxyOutSequence(MessageContext synCtx, ProxyService proxySe |
551 | 573 | return null; |
552 | 574 | } |
553 | 575 |
|
| 576 | + |
554 | 577 | public void setSynapseDebugMode(boolean synapseDebugMode) { |
555 | 578 | this.synapseDebugMode = synapseDebugMode; |
556 | 579 | } |
| 580 | + |
| 581 | + /** |
| 582 | + * Whether unit test is enabled in the environment. |
| 583 | + * |
| 584 | + * @return whether debugging is enabled in the environment |
| 585 | + */ |
| 586 | + public boolean isUnitTestEnabled() { |
| 587 | + return isUnitTestEnabled; |
| 588 | + } |
| 589 | + |
| 590 | + /** |
| 591 | + * set unit test mode enabled in the environment. |
| 592 | + * |
| 593 | + * @param isUnitTestEnabled boolean value of unit test mode |
| 594 | + */ |
| 595 | + public void setUnitTestEnabled(boolean isUnitTestEnabled) { |
| 596 | + this.isUnitTestEnabled = isUnitTestEnabled; |
| 597 | + } |
557 | 598 | } |
0 commit comments