Skip to content

Commit

Permalink
Merge pull request #82 from ayeshLK/jms-tests
Browse files Browse the repository at this point in the history
Add test cases for the `java.jms` module
  • Loading branch information
ayeshLK committed Aug 11, 2023
2 parents a8c4260 + 5f114c6 commit 29defe1
Show file tree
Hide file tree
Showing 23 changed files with 2,383 additions and 67 deletions.
12 changes: 12 additions & 0 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ groupId = "javax.jms"
artifactId = "javax.jms-api"
version = "2.0.1"
path = "./lib/javax.jms-api-2.0.1.jar"

[[platform.java11.dependency]]
path = "./lib/activemq-client-5.18.2.jar"
scope = "testOnly"

[[platform.java11.dependency]]
path = "./lib/geronimo-j2ee-management_1.1_spec-1.0.1.jar"
scope = "testOnly"

[[platform.java11.dependency]]
path = "./lib/hawtbuf-1.11.jar"
scope = "testOnly"
38 changes: 37 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,48 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.runtime"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "lang.runtime", moduleName = "lang.runtime"}
]

[[package]]
org = "ballerina"
name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
]

[[package]]
org = "ballerinax"
name = "java.jms"
version = "0.1.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.runtime"},
{org = "ballerina", name = "test"}
]
modules = [
{org = "ballerinax", packageName = "java.jms", moduleName = "java.jms"}
Expand Down
112 changes: 64 additions & 48 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ballerina {
packageOrganization = packageOrg
module = packageName
langVersion = ballerinaLangVersion
testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.stdlib.*:stdlib.java.jms*"
testCoverageParam = "--code-coverage --coverage-format=xml --includes=*"
}

configurations {
Expand All @@ -75,6 +75,19 @@ dependencies {
externalJars(group: 'javax.jms', name: 'javax.jms-api', version: "${javaxJmsVersion}") {
transitive = false
}

/**
Test related dependencies
*/
externalJars(group: 'org.apache.activemq', name: 'activemq-client', version: "${activemqClientVersion}") {
transitive = false
}
externalJars(group: 'org.apache.geronimo.specs', name: 'geronimo-j2ee-management_1.1_spec', version: "${geronimoJ2eeMng11SpecVersion}") {
transitive = false
}
externalJars(group: 'org.fusesource.hawtbuf', name: 'hawtbuf', version: "${hawtbufVersion}") {
transitive = false
}
}

task updateTomlFiles {
Expand All @@ -85,6 +98,9 @@ task updateTomlFiles {
newConfig = newConfig.replace("@toml.version@", tomlVersion)
newConfig = newConfig.replace("@slf4j.version@", stdlibDependentSlf4jVersion)
newConfig = newConfig.replace("@javax.jms.version@", stdlibDependentJavaxJmsVersion)
newConfig = newConfig.replace('@activemq.client.version@', project.activemqClientVersion)
newConfig = newConfig.replace('@geronimoj2ee.spec.version@', project.geronimoJ2eeMng11SpecVersion)
newConfig = newConfig.replace('@hawtbuf.version@', project.hawtbufVersion)
ballerinaTomlFile.text = newConfig
}
}
Expand All @@ -102,51 +118,51 @@ task commitTomlFiles {
}
}

//task startMqttServer() {
// doLast {
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// def stdOut = new ByteArrayOutputStream()
// exec {
// commandLine 'sh', '-c', "docker ps --filter name=mqtt-test"
// standardOutput = stdOut
// }
// if (!stdOut.toString().contains("mqtt-test")) {
// println "Starting Mqtt server."
// exec {
// commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml up -d"
// standardOutput = stdOut
// }
// println stdOut.toString()
// sleep(5 * 1000)
// } else {
// println "Mqtt server is already running."
// }
// }
// }
//}
//
//task stopMqttServer() {
// doLast {
// if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
// def stdOut = new ByteArrayOutputStream()
// exec {
// commandLine 'sh', '-c', "docker ps --filter name=mqtt-test"
// standardOutput = stdOut
// }
// if (stdOut.toString().contains("mqtt-test")) {
// println "Stopping Mqtt server."
// exec {
// commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml rm -svf"
// standardOutput = stdOut
// }
// println stdOut.toString()
// sleep(5 * 1000)
// } else {
// println "Mqtt server is not started."
// }
// }
// }
//}
task startActiveMQServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=activemq-test"
standardOutput = stdOut
}
if (!stdOut.toString().contains("activemq-test")) {
println "Starting ActiveMQ server."
exec {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml up -d"
standardOutput = stdOut
}
println stdOut.toString()
sleep(5 * 1000)
} else {
println "ActiveMQ server is already running."
}
}
}
}

task stopActiveMQServer() {
doLast {
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
def stdOut = new ByteArrayOutputStream()
exec {
commandLine 'sh', '-c', "docker ps --filter name=activemq-test"
standardOutput = stdOut
}
if (stdOut.toString().contains("activemq-test")) {
println "Stopping ActiveMQ server."
exec {
commandLine 'sh', '-c', "docker-compose -f tests/resources/docker-compose.yaml rm -svf"
standardOutput = stdOut
}
println stdOut.toString()
sleep(5 * 1000)
} else {
println "ActiveMQ server is not started."
}
}
}
}

publishing {
publications {
Expand All @@ -168,8 +184,8 @@ publishing {

updateTomlFiles.dependsOn copyStdlibs

//test.dependsOn startMqttServer
//build.finalizedBy stopMqttServer
test.dependsOn startActiveMQServer
build.finalizedBy stopActiveMQServer

build.dependsOn ":java.jms-native:build"
build.dependsOn "generatePomFileForMavenPublication"
Expand Down
13 changes: 9 additions & 4 deletions ballerina/message_producer.bal
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,27 @@ isolated function getJmsMessage(Session session, Message message) returns handle
return jmsMessage;
}

const string TEXT = "TEXT";
const string BYTES = "BYTES";
const string MAP = "MAP";

isolated function constructJmsMessage(Session session, Message message) returns handle|Error {
if message is TextMessage {
handle jmsMessage = check session.createJmsMessage("TEXT");
handle jmsMessage = check session.createJmsMessage(TEXT);
error? result = trap externWriteText(jmsMessage, java:fromString(message.content));
if result is error {
return error Error(result.message());
}
return jmsMessage;
} else if message is BytesMessage {
handle jmsMessage = check session.createJmsMessage("BYTES");
handle jmsMessage = check session.createJmsMessage(BYTES);
error? result = trap externWriteBytes(jmsMessage, message.content);
if result is error {
return error Error(result.message());
}
return jmsMessage;
} else if message is MapMessage {
handle jmsMessage = check session.createJmsMessage("MAP");
handle jmsMessage = check session.createJmsMessage(MAP);
error? result = trap populateMapMessage(jmsMessage, message.content);
if result is error {
return error Error(result.message());
Expand All @@ -101,7 +105,8 @@ isolated function constructJmsMessage(Session session, Message message) returns
return error Error("Unidentified message type");
}

isolated function updateReplyToMessageField(Session session, handle jmsMessage, Destination? replyTo = ()) returns Error? {
isolated function updateReplyToMessageField(Session session, handle jmsMessage,
Destination? replyTo = ()) returns Error? {
if replyTo is () {
return;
}
Expand Down
Empty file removed ballerina/resources/.keep
Empty file.
Loading

0 comments on commit 29defe1

Please sign in to comment.