Skip to content

Commit e52e860

Browse files
Add synapse unit testing framework
1 parent 0b3dec3 commit e52e860

27 files changed

+4303
-2
lines changed

modules/core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,9 @@
318318
<artifactId>xercesImpl</artifactId>
319319
<scope>test</scope>
320320
</dependency>
321+
<dependency>
322+
<groupId>com.google.code.gson</groupId>
323+
<artifactId>gson</artifactId>
324+
</dependency>
321325
</dependencies>
322326
</project>

modules/core/src/main/java/org/apache/synapse/ServerContextInformation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class ServerContextInformation {
4242
private ServerState serverState = ServerState.UNDETERMINED;
4343
/** Reference to the server configuration */
4444
private ServerConfigurationInformation serverConfigurationInformation;
45+
/** whether unit test mode is enabled or not */
46+
private boolean isUnitTestModeEnabled=false;
4547

4648
public ServerContextInformation(ServerConfigurationInformation serverConfigurationInformation) {
4749
this.serverConfigurationInformation = serverConfigurationInformation;
@@ -96,4 +98,12 @@ public void setSynapseEnvironment(SynapseEnvironment synapseEnvironment) {
9698
public ServerConfigurationInformation getServerConfigurationInformation() {
9799
return serverConfigurationInformation;
98100
}
101+
102+
public boolean isServerUnitTestModeEnabled(){
103+
return isUnitTestModeEnabled;
104+
}
105+
106+
public void setServerUnitTestModeEnabled(boolean isUnitTestModeEnabled){
107+
this.isUnitTestModeEnabled=isUnitTestModeEnabled;
108+
}
99109
}

modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.synapse.rest.RESTRequestHandler;
4545
import org.apache.synapse.task.SynapseTaskManager;
4646
import org.apache.synapse.transport.passthru.util.RelayUtils;
47+
import org.apache.synapse.unittest.UnitTestingExecutor;
4748
import org.apache.synapse.util.concurrent.SynapseThreadPool;
4849
import org.apache.synapse.util.xpath.ext.SynapseXpathFunctionContextProvider;
4950
import org.apache.synapse.util.xpath.ext.SynapseXpathVariableResolver;
@@ -83,6 +84,9 @@ public class Axis2SynapseEnvironment implements SynapseEnvironment {
8384

8485
private boolean synapseDebugMode;
8586

87+
/** Unit test mode is enabled/disabled*/
88+
private boolean isUnitTestEnabled = false;
89+
8690
public Axis2SynapseEnvironment(SynapseConfiguration synCfg) {
8791

8892
int coreThreads = SynapseThreadPool.SYNAPSE_CORE_THREADS;
@@ -126,7 +130,25 @@ public Axis2SynapseEnvironment(ConfigurationContext cfgCtx,
126130
public Axis2SynapseEnvironment(ConfigurationContext cfgCtx,
127131
SynapseConfiguration synapseConfig, ServerContextInformation contextInformation) {
128132
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+
}
130152
}
131153

132154
public boolean injectMessage(final MessageContext synCtx) {
@@ -551,7 +573,26 @@ private Mediator getProxyOutSequence(MessageContext synCtx, ProxyService proxySe
551573
return null;
552574
}
553575

576+
554577
public void setSynapseDebugMode(boolean synapseDebugMode) {
555578
this.synapseDebugMode = synapseDebugMode;
556579
}
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+
}
557598
}

0 commit comments

Comments
 (0)